Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome browser not sending 'If-None-Match' for xhr

I'm using an angular service to GET a resource via a rest api. The server sets the ETag header to some value and it also sets Cache-Control: no-cache in it's response.

This works as expected using Firefox, but when I access the same app using Chrome, it is not sending the If-None-Match. I've tried on current Chrome dev and stable channels on both a Mac and an Ubuntu box, and it was the same on both, while Firefox was adding the If-None-Match correctly.

Now, there are other non-xhr/static resources that are fetched conditionally and all those requests correctly get a 304 NOT MODIFIED response.

Is there anything I can do to get more information about why Chrome is not sending the If-None-Match header only for XHR requests?

like image 828
HK_ Avatar asked Aug 24 '13 02:08

HK_


1 Answers

If you're issuing an Ajax query in Chrome over HTTPS, any certificate errors, such as using a self-signed cert on your API server, prevent the response from being cached. This seems to be by design.

Evidently a Chrome defect existed but was fixed in Webkit and made it into Chromium / Chrome around 2010.

Another question recommends setting the If-Modified-Since and If-None-Match headers manually using jQuery's ifModified: true and cache: true options. Unfortunately this won't over-ride Chrome's intended behavior to not cache HTTPS responses from a server with a self signed certificate.

Testing on a server with a valid signed SSL certificate solved the issue for me; Chrome received 304's for text/html content as expected, using the default jQuery AJAX methods.

like image 197
Darren Avatar answered Oct 08 '22 07:10

Darren