In my Grails 3.2 application I found out that cookies set in after
and afterView
methods are not set.
My (simplified) controller:
class MyInterceptor {
boolean before() {
Cookie c = new Cookie('before', 'ok')
response.addCookie c
true
}
boolean after() {
Cookie c = new Cookie('after', 'ok')
response.addCookie c
true
}
void afterView() {
Cookie c = new Cookie('afterview', 'ok')
response.addCookie c
}
}
Only before
cookie is returned in set-cookie
response header.
Am I missing any kind of limitations of response
attribute in such methods?
The issue is when the after*
method are invoked the controller or view may have already written to the response such that the response has been committed and it is too late to add any headers or cookies.
This is not a limitation of Grails as such but the just the way servlet containers work.