I am implementing a REST API that should support cross-domain requests. Using CORS, I want to achieve this. Almost all of my requests are "not simple", which means for all requests other than GET, a pre-check request must be sent by the browser.
To limit the number of preflight / OPTIONS requests, I am trying to allow the browser to cache OPTIONS requests. This seems to work in Firefox and Safari, but not in Chrome. I know that Chrome will only cache pre-sales requests in just 10 minutes, but in my case, it doesn't seem to be caching at all.
These are the HTTP requests and responses sent / received by Chrome:
Request:
OPTIONS /api/v1/sessions HTTP/1.1 Host: xxxxxxx Connection: keep-alive Pragma: no-cache Cache-Control: no-cache Access-Control-Request-Method: POST Origin: http://localhost:8000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36 Access-Control-Request-Headers: content-type Accept: */* Referer: http://localhost:8000/ Accept-Encoding: gzip, deflate, sdch Accept-Language: nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Answer:
HTTP/1.1 200 OK Date: Sun, 26 Jul 2015 09:33:27 GMT Server: Apache/2.4.7 (Ubuntu) X-Powered-By: PHP/5.5.9-1ubuntu4.9 Cache-Control: private, max-age=1440, pre-check=1440 Access-Control-Allow-Origin: http://localhost:8000 Access-Control-Allow-Methods: GET,POST,PATCH,DELETE Access-Control-Max-Age: 86400 Access-Control-Allow-Headers: content-type Content-Length: 0 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html; charset=utf-8
google-chrome caching cors preflight
user23127
source share