Not sure when this started.
Adding to skip list. Please remove when this is fixed.
I suspect that CFNetwork is not giving us 206 responses when it already has complete ones cached.
A workaround for this bug is to suppress caching for each XHR with a Range header, using:
When running the layout test (and deleting the line in LayoutTests/platform/mac/TestExpectations that expects a failure), this is how the test fails:
@@ -1,9 +1,11 @@
Test Range support in XMLHttpRequest
getRange(resources/reply.xml, 34, 36, false)
-Length : expected 2 got 2
+Expected a 206 response, got 200
+Length : expected 2 got 68
getRange(resources/reply.xml, 35, 38, false)
-Length : expected 3 got 3
+Expected a 206 response, got 200
+Length : expected 3 got 68
getRange(resources/reply.xml, 34, 36, true)
Length : expected 2 got 2
getRange(resources/reply.xml, 35, 38, true)
Yesterday at WWDC, a developer asked a question about pdf.js being broken for Mac Safari 6.0.x and Safari for iOS 6.x. I believe this may be the bug that's causing that issue.
These are the relevant pdf.js bugs and commits that track the issue:
Pdf.js not working in safari browser on MAC OSX 10.8.2, safari version 6.0.1
Does not work on Safari mobile
Disable range request loading for safari.
Failing in Safari
I've just finished a long debugging session on a product that uses XHR range requests to fetch particular files from zip archives hosted on the server. I found a new work-around for the Safari bug. It has been tested and verified working on:
- OS X Mountain Lion - Safari Version 6.0.5 (8536.30.1)
- OS X Mavericks - Safari Version 7.0.1 (9537.73.11)
- iOS 7.0.6 (11B651)
The problem: the second request to the same file for a different range returns the same contents as the first one. Safari wrongly reports "Cached: no" in the relevant line of the network tab of the developer tools. It also ignores "pragma=no-cache" headers, if added.
The solution: I succeeded in making it throw away the old request by making each request unique. I accomplished this by generating a random string and adding the following header: If-None-Match: "<random string>".
After this change Safari began returning the right contents from the new specified range of the file.
This should let the web developers deploy a new and better work-around for their products instead of resorting to disabling range requests altogether. I also hope it can help the webkit developers in pin-pointing where this problem stems from.
This tests passes on Yosemite with both WK1 and WK2. But it still fails in Safari.
This may mean that HTTP caching is somehow broken in regression tests on Yosemite, which hides the problem.
Note that https://github.com/gildas-lormeau/zip.js/pull/91/files uses the following header as a work-around:
which may be more interoperable with other browsers.
Note there is a similar issue with the Vary header:
I've found that this bug can at least be easily detected at runtime by checking the HTTP status code and Content-Range response header against the expected values. You can then issue a second request with caching disabled and continue on, without hardcoding assumptions about User-Agent strings.
In ogv.js <https://github.com/brion/ogv.js/commit/9ab5bce2f99f13a82a07ab83eeae77ede031e620> I'm using such a check to only apply cache-busting if the bug is actually encountered.
At least on OS X 10.10 I'm seeing the bug only after reaching the *end* of the file; so for the ogv.js media player case this doesn't hit until a second playthrough, unless the file is missing index information in which case a seek to the end is used to calculate the duration before playback begins.
(Note I'm using a query-string as cache-buster so that the request will still be cacheable on the server-side proxy cache; though not ideal it seems to be working.)
I'm getting the same behavior in a native iOS app using NSURLConnection to download chunks with a Range: header, so this indeed seems to be a low-level CFNetwork caching issue...
WebKit has a new network cache, and this bug is fixed in that implementation via:
Bug 144682: Network Cache: Layout Test http/tests/xmlhttprequest/range-test.html is failing
Please try WebKit Nightly build at <http://nightly.webkit.org/> to verify.
We're still tracking the NSURLCache issue via Radar (<rdar://problem/11150946>).
Marking as forward dupe for tracking purposes.
*** This bug has been marked as a duplicate of bug 144682 ***
(In reply to comment #13)
> WebKit has a new network cache, and this bug is fixed in that implementation
> Bug 144682: Network Cache: Layout Test
> http/tests/xmlhttprequest/range-test.html is failing
> Please try WebKit Nightly build at <http://nightly.webkit.org/> to verify.
Looks good with a current nightly -- my workaround from comment 11 gracefully disables itself. Thanks!
> We're still tracking the NSURLCache issue via Radar