Reputation: 2382
In my Grails app I'd like to make a custom request filter that looks for an existing 'Location' redirect header and modifies it if the response has not yet been committed.
I don't see a method on the response object to even READ the existing headers, much less overwrite them.
Is there a way to do this?
Thanks!
Upvotes: 1
Views: 1564
Reputation: 597016
This is done by creating a wrapper (extending HttpServletResponseWrapper
) and overrideing the setHeader(..)
method. There you can replace the header right before it is added to the response.
The wrapper is utilized by creating it in a filter:
chain.doFilter(request, new ResponseWrapper(response))
Upvotes: 2