5

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
2
  • Did you ever figure this out? We're having exactly the same problem with images in Safari 5.1.5
    – Howard
    Commented Jun 28, 2012 at 11:09
  • Maybe check if disableCaching is set to true for your connection. If true, it adds a _dc=3487394384 like parameter to your GET parameters. This forces the URL to always be unique. The browser apparently thinks the resource you are requesting has not changed, with a unique URL this should not happen Commented Jan 10, 2013 at 10:23

1 Answer 1

0

Great research work. What you see is an Ajax Redirection & normally you cannot see it in most developer tools but nevertheless it happens. Ideally it should have no effect on your application, in your question I don't see you reporting any problems or errors just more requests.

This redirection is handled at the browser level so there is nothing you can do about it(I have tried in the past and could not do anything about it).

This is not a sencha issue btw but how Ajax behaves.

Hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.