Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upResponse content-length header almost always wrong #67
Comments
|
So Currently Fixing it for the Cache API but not for network responses seems wrong. I think fundamentally when you have an object the header should not be relevant anymore, but the original value might still be interesting for debugging purposes. I wonder if @sleevi has any ideas. |
|
@annevk Not sure what you meant by
You're just talking about I suspect there may be all sorts of weirdness. For example, if a Network request was chunked in the Response, should that be preserved in the Response object if it was loaded from the Cache? Presumably you shouldn't have to preserve the same boundaries - they could just be handled transparently? |
|
Yes, just |
|
Yeah, HTTP range requests were the other thing I was thinking about, particularly as they relate to the use of MPEG DASH (which, depending on the serving infrastructure, may either use multiple separate URLs for chunks or use Range requests with a single streaming URL). If you wanted to, say, allow offline streaming (ignoring the ever looming DRM question for 'meaningful' streaming), how would developers want to interact with the Cache, versus what are the security implications of allowing SW control over Range requests (there have been interesting security interactions with Range in the past) |
|
@wanderview what does the HTTP cache do here? Does it retain the original The cache API should be able to produce partial responses for range requests. This would work very well with media elements. I'm less sure about changing the transfer encoding & content-length. |
|
@jakearchibald the http cache generally stores the on-the-wire data for the response. It does not strip gzip, etc. This is much harder for Cache API to achieve since we get a Response where Response.body has gzip/etc decoded already. Also, the Response could be synthetic, etc. So the http cache case has the correct content length because its using the on-the-wire format. |
|
The tentative resolution here is that browser implementations should only use Any objections? |
|
Sounds good. I think we at least need the note to signal intent here. Otherwise it could get confusing for people trying to lock down content-length in the network stack down the line. |
|
Shall I put the note as part of https://fetch.spec.whatwg.org/#concept-http-network-fetch or would you like it elsewhere? |
|
HTTP Network Fetch section sounds reasonable. Thanks. |
|
Thank you! |
|
@annevk I don't understand the note.
|
|
@Mouvedia this issue should answer those questions, but the context of the note should as well. If you potentially transform the response before returning it (as implementations do), but keep headers as-is, |
|
So the definition of what the @annevk I am interested in its value during streaming; if exposed, sent and accurate will it still be equivalent to XHR's |
|
What @Mouvedia it should never be different from ProgressEvent's total for H/1 connections at least. I'm not sure how H/2 deals with incorrect |
|
Interesting, I didn't know that the |
|
It doesn't get overwritten? |


While debugging various issues in our SW implementation I've noticed that we get a lot of warnings about bad content-length headers. It seems this might be a consequence of the current spec:
This problem is propagated through things like the Cache API which preserve the headers.
Should we consider fixing up the content-length header once we know the full length of the stream? Or force Response to always use chunked encoding?
Right now I think this is just a nuisance, but it seems it could cause problems in the future.