I’m using sessions in my Catalyst app via Session, Session::Store::DBIC, and Session::State::Cookie.
I have a few controllers and methods that send out data with a Cache-Control: public header, so its essential that the Set-Cookie: header not go out with those responses (otherwise, it’d be cached and sent to other clients, leading to possible security issues). I haven’t found a good way to accomplish this.
How can I tell Session or Session::State::Cookie to not send a cookie in response to a given request?
Doing a little RTFS,
Session.pmoverrides Catalyst’sfinalize_headersmethod and sets the cookie there, through a rather deep call chain:
There does not appear to be any way to flag anything in the chain to
stop. The only check is a method in
Cookie.pmcalledcookie_is_rejectingwhich just compares the configured cookie path tothe request path.
So, it looks like the best way to do this is to add my own override to
either
update_session_cookieorcookie_is_rejecting. I think I’lluse
cookie_is_rejecting.Here is the code I finally used. Note that this is rather klugy, but it works…