In my controller action i tried to set the contentType of the response as below.
class MyController {
def rss = {
response.setContentType('text/xml')
//I even tried setHeader('contentType') and also render(contentType:'text/xml',...)
render(template:'/displayRss', model:[:])
}
}
In the filter i tried to set the header for all controller and action params
class Filter {
def filters = {
all(controller:'*', action:'*'){
after = {
response.setHeader('Cache-Control', 'no-cache')
}
}
}
}
Header is added for all other actions except for the action in which response contentType is modified. It seems like response.isCommitted() is returned as true in that action alone. Am i am not understanding the basic of rendering...?
Also this is not the case if i use render(view:'/abc') instead of view(template:'/abc', model:[:])
Thanks in advance
It looks like rendering a template sends the template immediately when called, as it's showing up as already committed in the filter. Since it's committed the headers have already been sent and setting a header after the fact doesn't make sense, so the setHeader in the Filter gets ignored.
My guess is this is a peculiarity to rendering templates specifically, and in those cases you'll need to set the cache header in the controller action explicitly, or use view rendering instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With