I am trying to add a custom HTTP header to the response of a certain set of controllers using Grails Filters:
class ApiFilters {
def filters = {
xwingFilter(uri:'/api/**') {
after = {
response.setHeader('X-Wing', 'foo')
}
}
}
}
If the controller renders a view or text, the header gets added to the response. If the controller uses "render as JSON" the header is not added. It looks like the JSON converter is closing the output stream and sending it right away. Is that right?
I could use Grails interceptors but I'd have to replicate it in more than one controller. Any ideas on how can I achieve this?