Repository navigation
drop a passed-through Content-Length when the client reframes the body - #2679
Open
metsw24-max wants to merge 1 commit into
Open
metsw24-max wants to merge 1 commit into
metsw24-max wants to merge 1 commit into
Conversation
send_with_content_provider_and_receiver() kept a Content-Length the caller passed through after the library reframed the body: it compresses a buffered body under set_compress(true), or streams a provider without a length as chunked. prepare_default_headers() only adds a Content-Length when none is present, so the stale value went out describing the original body. With compression the server reads only that many bytes of the longer gzip stream and the rest desyncs the next request on a kept-alive connection; with a chunked provider the client emits both Content-Length and Transfer-Encoding. Erase it once the library owns the framing so write_request() emits the matching length, or none for a chunked body. A plain, uncompressed body keeps the caller's value.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A stale Content-Length survives when the client reframes a request body
When a caller forwards a request's headers through
Post/Put/Patch, theContent-Lengthit passes through is kept even after the client reframes the body inClientImpl::send_with_content_provider_and_receiver: withset_compress(true)the buffered body is replaced by its gzip stream, and a content provider without a length is sent asTransfer-Encoding: chunked.prepare_default_headersonly adds aContent-Lengthwhen none is present, so the forwarded value goes out describing the original body rather than what is on the wire. Passing aContent-Lengththrough is supported usage;ServerTest.NoMultipleHeadersdoes exactly that. For a compressed body the gzip stream is longer than the plaintext it came from, so a server readingContent-Lengthbytes takes only the first part and parses the remainder as the next request on a kept-alive connection, which desyncs it; for a chunked provider the client emits bothContent-LengthandTransfer-Encoding, the ambiguous framing a server rejects. The fix erasesContent-Lengthin that function once the library owns the framing, sowrite_requestemits the length that matches the compressed body, or none for a chunked one; a plain, uncompressed body keeps the caller's value.ClientRequestFramingTest.CompressedBodyReplacesCallerContentLengthandChunkedProviderDropsCallerContentLengthfail on the current header and pass with the fix.This looks like a sibling of #2581, which rejected the same ambiguous framing when reading a response; it seems worth closing on the request-writing side as well.