I have a REST Java server implemented with Jersey running on Jetty. It seems that certain browsers (IE7) internally caches all requests made to the server.
What I would like to do is to send a certain HTTP header in the response from the REST server indicating the browser that it shouldn't cache that response, and so will query the server again the next time it needs access to that resource.
Any ideas on how to configure Jersey/Jetty for this? Or the only way to configure it is client-side?
response.setHeader("Pragma", "no-cache");
No, No. No!
The use of the pragma header to disabling client side caching is wrong, it's a request header and has zero effect on the response.
http://www.mnot.net/cache_docs/#PRAGMA
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32
Also, setting Expires: 0 isn't correct, Expires should be a date, not a number of seconds, however this will work as an invalid http date is interpreted as "already expired"
http://www.mnot.net/cache_docs/#EXPIRES
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21
There's nothing you can do about rogue clients, but Jetty can send the appopriate HTTP headers. Try here for info on configuring the Last-Modified and Cache-Control headers.
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