SUMMARY: Safari reports 304 response even though it receives 200 on XHR requests
Hello - I have a bizarre situation with Safari, and have hit the end of the road trying to research it myself, I'm hoping someone here has encountered this in the past.
I've currently started using my application (a thick Sencha Touch client talking to a RESTful API served by NodeJS) in Safari and noticed that browser is occasionally (actually: about 5 times out of 6) mis-handling server responses, and reporting them (in the developer tools network console) as 304 responses with no content, instead of the 200 responses with JSON content that are actually being delivered. (And the application is behaving accordingly - the content-less 304 responses cause the application to assume it got no data, and it responds that way, so it's not just a cosmetic issue in the developer panel.)
The headers are not even correct - here are the disjoint set of Response headers reported by Safari for the two cases (I've confirmed that the request contents and headers are identical for the two):
200
- Access-Control-Allow-Credentials:true
- Access-Control-Allow-Headers:*
- Access-Control-Allow-Methods:GET,POST,UPDATE,DELETE,OPTIONS
- Access-Control-Allow-Origin:undefined
- Content-Length:2
- Content-Type:application/json; charset=utf-8
304
- Content-Type:text/javascript
- Last-Modified:Sun, 20 Nov 2011 22:30:45 GMT
- Server:lightnode
- Transfer-Encoding:Identity
(I've omitted response headers that are identical between the two.)
A Few Other Notes
- I've verified that the responses sent by the server are identical on every request, and have tcpdump'ed the traffic and confirmed that the server is sending 200 response codes (and headers) that are then being reported and handled by Safari as 304 responses sans content (and with the bogus headers above.) Safari is reporting a response that was never sent.
- The 304 headers above look similar to what might be sent along with static content in this application, but I have confirmed that both responses are being served by the same code path (the API server, ie, no "lightnode" involved, those headers are being made up by Safari.)
- I don't ever see this behavior in Chrome
- I've confirmed the same buggy application behavior on Mobile Safari (for which Sencha Touch is built, along with all other WebKit browsers like Safari and Chrome), but haven't been able to confirm the bogus response handling specifically since iOS doesn't really expose this low-level debugging information.
- There are no XSS/CORS issues here, the API and static content are all served from the same domain.
- Yes, I've done all of the usual clear cookies/cache/restart/etc initialization stuff, has no effect.
Versions
- Safari: 5.1.1
- OSX: 10.7.2