HTTP client form upload should not send a chunked transfer encoding header on HTTP/3 - #6316
Open
jnbdz wants to merge 1 commit into
Open
Conversation
…eader on HTTP/3 Motivation: The client multipart form encoder produces an HTTP/1.1 request whose headers are copied on the HttpClientRequest, including a chunked transfer-encoding header when the form is streamed. That header is a connection specific header forbidden by HTTP/2 and HTTP/3. HTTP/2 client streams sanitize it since a5afe84, however HTTP/3 client streams do not and a chunked multipart form upload sends transfer-encoding: chunked on the wire. Fixes eclipse-vertx#5690. Changes: Translate the encoder chunked transfer-encoding header into a chunked request with setChunked(true) instead of copying it: the HTTP/1.1 client connection still writes the header from the chunked flag while HTTP/2 and HTTP/3 never see it. Remove a transfer-encoding header in the HTTP/3 client stream before writing the request head, like the HTTP/2 client stream does. Assert in the shared client file upload tests that HTTP/1.1 uploads carry the chunked transfer encoding and that HTTP/2 and HTTP/3 uploads carry no transfer-encoding header, and add an HTTP/3 client test for a manually set transfer-encoding header.
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.
Motivation
HttpClientRequest#send(ClientForm)builds the body with Netty'sHttpPostRequestEncoder, which produces an HTTP/1.1 request; the encoder headers are then copied on the request, includingtransfer-encoding: chunkedwhen the form is streamed (file uploads). That header is a connection specific header forbidden by HTTP/2 (RFC 9113 §8.2.2) and HTTP/3 (RFC 9114 §4.2).HTTP/2 client streams have sanitized it since a5afe84 (5.0.2), but HTTP/3 client streams do not: a chunked multipart form upload over HTTP/3 currently sends
transfer-encoding: chunkedon the wire (the Vert.x server tolerates it, which is why the existing HTTP/3 upload tests did not catch it).Fixes #5690.
Changes
HttpClientRequestImpl#send(ClientForm): instead of copying the encoder'stransfer-encoding: chunkedheader, the request is switched to chunked mode withsetChunked(true). The HTTP/1.1 client connection still writes the header from the chunked flag, HTTP/2 and HTTP/3 never see it — this fixes the problem at the source for every protocol.Http3ClientStream#writeHead: remove atransfer-encodingheader before writing the request head, mirroringDefaultHttp2ClientStream, so a manually set header is sanitized as well.Tests
HttpClientFileUploadTesthelper now asserts per protocol: HTTP/1.1 uploads carrytransfer-encoding: chunked, HTTP/2 and HTTP/3 uploads carry notransfer-encodingheader. Without the change, the 8 chunked upload cases ofHttp3ClientFileUploadTestfail withexpected null, but was:<chunked>; HTTP/1.1, HTTP/2, HTTP/2 multiplex and h2c upgrade variants are unaffected.Http3ClientTest#testChunkedTransferEncodingHeaderIsSanitized: a request with a manually settransfer-encoding: chunkedheader must not have it delivered to the server.Http1xTest,Http2Test, thehttp3andfileuploadtest packages pass locally.