Closed
Bug 475444
Opened 16 years ago
Closed 12 years ago
HTTP standard violation, Content-length header appears to be ignored under some circumstances
Categories
(Core :: Networking: HTTP, defect)
Tracking
()
RESOLVED
FIXED
mozilla17
People
(Reporter: zextra, Assigned: michal)
References
()
Details
Attachments
(1 file, 2 obsolete files)
3.89 KB,
patch
|
Biesinger
:
superreview+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.43 Safari/525.19
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
I have my own little application server. Although the way I have discovered this was due to a bug in my own software, here's a rundown of why do I think this is a violation of standard. Of course, it's not up to me to decide if it's a real bug or a feature.
On every valid HTTP request, my server sent valid HTTP response back to the client (I have Firefox as one of my client browsers).
Example of request URI:
http://localhost:1313/index.php?action=test
Example response:
-----start of response------
HTTP/1.1 200 OK
Content-Length: 37
Connection: close
Content-Type: application/json
test({"volid":"6C9DDEE2","oldsid":"57cabb368034fa07b18e5daf032d1547","newsid":""
,"ver":"1.1"})
-----end of response-------
So, a typical JSON response. But, one might notice that content-length header contains value a lot smaller than actual body size, which is 94 (that's because of a bug in my software, but I don't believe it matters in this case).
Nevertheless, Firefox did grab whole body, irregardless of size specified in content-length. For instance, I have tested same behavior with IE7 and wget, and they both conform to the standard specification (they have grabbed only first 37 bytes of content).
http://www.w3.org/Protocols/HTTP/1.0/spec.html#Content-Length
Because these circumstances are quite rare today, I haven't been able to confirm this behavior anywhere else except in my own lab conditions. But it should be as simple as writing
Reproducible: Always
Steps to Reproduce:
1. make sure that you have a http server which returns smaller content-length value than size of the body is
2. open up a browser
3. enter exact url leading to mis-generated resource in address bar
4. compare received content size to specified content-length specified in header
Actual Results:
content body is received in full
Expected Results:
content body should be received up to the length specified in content-length header
Updated•16 years ago
|
Component: General → Networking: HTTP
Product: Firefox → Core
QA Contact: general → networking.http
Comment 1•16 years ago
|
||
I cannot reproduce it on linux, neither with 3.0.5, neither with latest trunk.
I've set up a test similar to the one you described (except I use text/plain to make it easier to see in firefox) on http://www.fdn.fr/~arenevier/bugs/mozilla_475444.php On that url, I only see 37 characters.
You're right, same happens for me on given url.
Can you try sending exactly the same headers (including content-type and connection: close) as well? It could be related in some way...
Another suggestion might be to try with content length just slightly smaller than real content length (I know that it shouldn't matter, but who knows).
I'll play more with my local app and report back on my findings.
Comment 3•16 years ago
|
||
Hi,
looks like Connection:close is the triggering header:
http://www.fdn.fr/~arenevier/bugs/mozilla_475444-2.php
(I also tested with content-type: application/json, but results are the same)
Updated•16 years ago
|
I don't understand if you're able to confirm this by sending connection: close or not?
Anyway, here are few more things. What I noticed when I tested output of your first url via telnet, is that web server stops sending data after specified content-length, and since it's keep-alive connection, it waits for some specified interval, flushes rest of the output, and closes the connection.
When connection: close is sent (second url), whole output is sent at once, thus fulfilling required step number 1. But, even then, I'm still unable to reproduce it using firefox.
For the sake of confirmation, I've exposed my app to public, try testing it using following url:
http://zextra.ath.cx:54321/index.php?action=none
Server response:
------begin-------
HTTP/1.1 200 OK
Content-Length: 88
Connection: close
Content-Type: application/json
none({"volid":"6C9DDEE2","oldsid":"5dcbf65634d694e521069d29e72c95cb","newsid":"","ver":"1.1"})
--------end-------
It still confirms unexpected behavior for me.
Anyhow, I'm not quite sure how important this very special case and deviation from standard really is... What do you think?
Assignee | ||
Updated•16 years ago
|
Assignee: nobody → michal
Assignee | ||
Comment 5•16 years ago
|
||
This seems to be a feature and not a bug:
http://hg.mozilla.org/mozilla-central/annotate/94678a2f5ae9/netwerk/protocol/http/src/nsHttpTransaction.cpp#l934
But maybe the behavior should be different for HTTP/1.1, see https://bugzilla.mozilla.org/show_bug.cgi?id=83960#c8
Assignee | ||
Comment 6•16 years ago
|
||
Content-Length header is ignored only in case of HTTP/1.0 when connection isn't persistent.
I tried to write unittest but unfortunately testing httpd doesn't allow to set incorrect Content-Length header. It always computes correct value from bodyInputStream.
Attachment #367937 -
Flags: review?(bzbarsky)
Assignee | ||
Updated•16 years ago
|
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
![]() |
||
Comment 7•16 years ago
|
||
I think Waldo's working on a patch that would let you set bogus content-lengths...
![]() |
||
Comment 8•16 years ago
|
||
Comment on attachment 367937 [details] [diff] [review]
patch v1
Looks ok, but I'd like Christian to take a look too.
Attachment #367937 -
Flags: superreview?(cbiesinger)
Attachment #367937 -
Flags: review?(bzbarsky)
Attachment #367937 -
Flags: review+
Comment 9•16 years ago
|
||
Comment on attachment 367937 [details] [diff] [review]
patch v1
It's not like HTTP 1.1 gets this always right, but all cases I've seen the additional data is just garbage (and is generally on keepalive connections anyway. see bug 254181 et al)
Attachment #367937 -
Flags: superreview?(cbiesinger) → superreview+
Comment 10•16 years ago
|
||
(In reply to comment #7)
> I think Waldo's working on a patch that would let you set bogus
> content-lengths...
With bug 396226 that'll be possible, but the most future-proof solution will be in bug 484027, which will let you send whatever random junk you want to the HTTP client, in whatever format you want, and the server won't make any attempt to ensure any formatting whatsoever -- you get complete control except possibly for connection timeouts. That you can set a bogus Content-Length with only the former is a side effect more than an intended result, and eventually that sort of thing will probably be broken when I implement chunked responses and keepalive connections (the latter of which has already been directly requested, so it's not just a hypothetical feature).
Assignee | ||
Updated•16 years ago
|
Depends on: 484027
Keywords: checkin-needed
Comment 11•16 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.2a1
Comment 12•16 years ago
|
||
This is causing lots of talos crashes, e.g.
http://tinderbox.mozilla.org/showlog.cgi?log=Firefox/1238943422.1238945288.3595.gz
Going to backout...
Updated•16 years ago
|
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Assignee | ||
Comment 13•16 years ago
|
||
The problem is that nsHttpTransaction::TakeResponseHead() nulls out mResponseHead. I didn't notice that and it didn't crash on small web pages :-/
Attachment #367937 -
Attachment is obsolete: true
Attachment #371357 -
Flags: review?(bzbarsky)
![]() |
||
Comment 14•16 years ago
|
||
Comment on attachment 371357 [details] [diff] [review]
patch v2
Michal, you probably want to add the following to your .hgrc to make your hg export patches more readable:
[diff]
showfunc = true
unified = 8
r=me
Attachment #371357 -
Flags: review?(bzbarsky) → review+
Assignee | ||
Comment 15•16 years ago
|
||
Right! I had in my .hgrc
[defaults]
diff=-p -U 8
but this option doesn't take effect for hg export
Attachment #371357 -
Attachment is obsolete: true
Attachment #371486 -
Flags: superreview?(cbiesinger)
Updated•13 years ago
|
Attachment #371486 -
Flags: superreview?(cbiesinger) → superreview+
Assignee | ||
Comment 16•12 years ago
|
||
Comment 17•12 years ago
|
||
Status: REOPENED → RESOLVED
Closed: 16 years ago → 12 years ago
Resolution: --- → FIXED
Target Milestone: mozilla1.9.2a1 → mozilla17
You need to log in
before you can comment on or make changes to this bug.
Description
•