Dean Moses
Dean Moses

Reputation: 2382

Grails: can I modify existing HTTP headers in an uncommitted response?

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

Answers (1)

Bozho
Bozho

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

Related Questions