Closed Bug 733259 Opened 14 years ago Closed 4 years ago

jQuery and Headers with Content-Range Handling

Categories

(Core :: Networking: HTTP, defect, P3)

12 Branch
defect

Tracking

()

RESOLVED INCOMPLETE
Tracking Status
platform-rel --- -

People

(Reporter: sys.sgx, Unassigned)

Details

(Whiteboard: [necko-backlog] [platform-rel-jQuery])

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 6.0; rv:10.0.2) Gecko/20100101 Firefox/10.0.2 Build ID: 20120215223356 Steps to reproduce: Run this piece of code: ------------------------- <!DOCTYPE html> <html> <head> </head> <body> <textarea id="sometext"></textarea> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ $.ajax({ type: "GET", url: "somefile.xml", dataType: "html", headers: {Range: "bytes=0-100"}, success: function(xml) { $("#sometext").html(xml); } }); }); </script> </body> </html> --------------------------------------------------------- It should work, because it does in chrome 19. Actual results: Document displayed in a weired way, did not get only the exact range specified. Expected results: Only the requested bytes should have been placed in the textarea of the page.
Severity: normal → major
OS: Windows Vista → All
If someone here participates to the jQuery dev team, you could also try to better document which http headers are valid for ajax requests from a page.
Here's a version without jQuery. I hope I got it right! --- let r = new XMLHttpRequest(); r.open("GET", "http://www.mozilla.org/", true); r.setRequestHeader("Range", "bytes=0-100"); r.onreadystatechange = function (oEvent) { if (r.readyState === 4) { if (r.status === 200) { console.log("Output is " + r.responseText.length) } else { console.log("Error: " + r.status, r.statusText); } } }; r.send(null); --- Output in Web Console when viewing www.mozilla.org: [18:41:33.305] Output is 29091 The whole page content is logged if you drop the ".length". It would be good if someone tried this against a server known to support the Range header! Panagiotis, could you try, please?
Attached image example of http headers
The code in my example was actually a local file:/// request :-) so you can also check this. Here's your code: --------------------------- <!DOCTYPE html> <html> <head> </head> <body> <script> var r = new XMLHttpRequest(); r.open("GET", "http://www.mozilla.org/", true); r.setRequestHeader("Range", "bytes=0-100"); r.onreadystatechange = function (oEvent) { if (r.readyState === 4) { if (r.status === 200) { console.log("Output is " + r.responseText.length) } else { console.log("Error: " + r.status, r.statusText); } } }; r.send(null); </script> </body> </html> -------------------------- It does work in chrome, but not in firefox 10.0.2. Might have to do something with the way the content is requested. Let me know for any updates on this. Thanks
In your first comment, you said "[18:41:33.305] Output is 29091"; which version/platform are you at? Also, the request was for 100 bytes, why is r.responseText other than this value? Sometimes it gets the content, and with an example I checked, the content even changed the window title. See the example image for the http headers information.
(In reply to sys.sgx from comment #5) > In your first comment, you said "[18:41:33.305] Output is 29091"; which > version/platform are you at? Aurora 12. > Also, the request was for 100 bytes, why is r.responseText other than this > value? Beats me. Most likely www.mozilla.org is ignoring the Range header. This was just me drafting a piece of code that would run, without taking a dependency on jQuery.
(In reply to sys.sgx from comment #4) > The code in my example was actually a local file:/// request :-) so you can > also check this. Can you reproduce this bug against an actual HTTP server? A test case that points to a real server is important here. (Otherwise, this actually sounds like "XmlHTTPRequests against file: URIs don't respect the HTTP Range header", which is a much less significant issue IMO.)
I checked the file in a local server on my machine, same response. Does the request has to comply with the same origin rules? We have to find a server that accepts range headers for sure.
Priority: -- → P2
Hardware: x86 → All
Version: 11 Branch → 12 Branch
Any news on this issue? thanks
The code posted should not work for file:// URIs. For an HTTP server, it depends on the server response. What news were you expecting?
Richard said "A test case that points to a real server is important here." If you tried it on a server and it does work then it's ok for the server side :) But why shouldn't the code work for file:// URIs?..
Because HTTP headers make no sense for non-HTTP URIs.
you're right, but plz note that it's an easy way to test some things. (btw webkit browsers do support it)
one more thing to add: there's also an issue with how the browser handles such xml files (with http headers). I got an example xml file that when requesting it with headers, the *window title* changes; this might mean code is parsed differently.
Here's the example: -----------------------<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> </head> <body> <textarea id="ajaxget"></textarea><br> <div id="thisdiv"></div> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ $.ajax({ type: "GET", url: "rawfile.xml", dataType: "html", headers: {Range: "bytes=204-10197"}, success: function(xml) { $("#ajaxget").val(xml); $("#thisdiv").html(xml.replace("<![CDATA[","").replace("]]>","")); } }); }); </script> </body> </html> ------------------------------- I've attached the xml file. There seems to be a parse issue, because for some reason the title of the page changes, whereas in webkit it displays good.
Attached file rawfile
Whiteboard: [necko-backlog]
Whiteboard: [necko-backlog] → [necko-backlog] [platform-rel-jQuery]
platform-rel: --- → ?
platform-rel: ? → -
Priority: P2 → P1
Priority: P1 → P3

Closing this as resolved > incomplete. The real last activity on this issue was 10 years ago and it might not be relevant anymore.

Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: