You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SocketsHttpHandler does not check for Transfer-Encoding: chunked on response properly #63053
For every HTTP/1.1 response, we need to check for Transfer-Encoding: chunked. We do this by calling HttpHeaders.ContainsParsedValue.
This check will succeed if "chunked" appears anywhere in the Transfer-Encoding list. However, Transfer-Encodings are ordered and so the check should only succeed if "chunked" is the final Transfer-Encoding value.
Note that sending "chunked" as a non-final Transfer-Encoding value is invalid server behavior, so we are only doing this incorrectly when the server is misbehaving. Still, we should adhere to the RFC here.
Note this applies to both the public HttpResponseHeaders.TransferEncodingChunked property as well as our internal handling of Transfer-Encoding: chunked in HttpConnection (which uses the TransferEncodingChunked property today). We should ensure both are fixed.
Note also, this applies to setting the HttpResponseHeaders.TransferEncodingChunked property as well. It should only remove "chunked" if it is the final Transfer-Encoding value.
I was trying to understand risks of proposed solution in #105647
In order to do that I have studied how common HTTP Client handle Transport-Encoding, created some simple local HTTP server and tested it.
I have found that Transport-Encoding other than chunked is not implemented in any well used HTTP client. I have tested Chrome, Safari and curl and looked at source code of Kestrel and HttpClient.
I came to conclusion that current behavior of HttpClient is consistent with other major endpoint HTTP client implementations, i.e. if chunked appears in any order in Transfer-Encoding response is considered chunked.
If a Transfer-Encoding header field is present in a response and the chunked transfer coding is not the final encoding, the message body length is determined by reading the connection until it is closed by the server.
BUT, this was internally found and not reported by anyone, so I'm fine with keeping our behavior as-is.
I'm also fine with closing this. In case we have anyone reporting issue with the current behavior, we can always revisit this decision.
Activity
geoffkizer commentedon Dec 21, 2021
Note this applies to both the public HttpResponseHeaders.TransferEncodingChunked property as well as our internal handling of Transfer-Encoding: chunked in HttpConnection (which uses the TransferEncodingChunked property today). We should ensure both are fixed.
MihaZupan commentedon Dec 21, 2021
Related: We should likely invert the order of checking
Content-LengthandTransfer-Encodingwhen both are present: #62906 (comment)geoffkizer commentedon Dec 21, 2021
Note also, this applies to setting the HttpResponseHeaders.TransferEncodingChunked property as well. It should only remove "chunked" if it is the final Transfer-Encoding value.
karelz commentedon Jan 18, 2022
Triage: Corner case, but still a bug.
rokonec commentedon Jul 29, 2024
This has been already fixed
rokonec commentedon Aug 5, 2024
I was trying to understand risks of proposed solution in #105647
In order to do that I have studied how common HTTP Client handle Transport-Encoding, created some simple local HTTP server and tested it.
I have found that
Transport-Encodingother thanchunkedis not implemented in any well used HTTP client. I have tested Chrome, Safari and curl and looked at source code of Kestrel and HttpClient.I came to conclusion that current behavior of
HttpClientis consistent with other major endpoint HTTP client implementations, i.e. ifchunkedappears in any order inTransfer-Encodingresponse is consideredchunked.For this reason I see any functional changes to current behavior as risky, same as chromium authors did in https://issues.chromium.org/issues/40620688
I therefore recommend to close this issue and linked PR as by-design.
@MihaZupan @karelz @ManickaP
ManickaP commentedon Aug 8, 2024
I did some RFC reading and this part is interesting [6.3. Message Body Length](https://httpwg.org/specs/rfc9112.html#message.body.length) point 4.:
BUT, this was internally found and not reported by anyone, so I'm fine with keeping our behavior as-is.
I'm also fine with closing this. In case we have anyone reporting issue with the current behavior, we can always revisit this decision.
MihaZupan commentedon Aug 12, 2024
👍 as we've discussed, I agree changing this would be risky. Thanks for checking how other implementations behave here.