fix: skip CRT Content-Length when chunked#7173
Merged
Merged
Conversation
The CRT async request adapter synthesized a Content-Length from the request body publisher even when the request already carried Transfer-Encoding: chunked. Emitting both headers violates RFC 7230 and was rejected by the underlying CRT layer. Skip Content-Length when Transfer-Encoding is present, aligning the CRT client with the Netty client, which never synthesizes Content-Length for a chunked request. Adds unit coverage for the adapter and HTTPS functional tests for the sync and async CRT chunked paths.
davidh44
approved these changes
Jul 21, 2026
jencymaryjoseph
approved these changes
Jul 21, 2026
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 and Context
When the AWS CRT-based async HTTP client sends a request with a body of unknown
length, the SDK marshals it with
Transfer-Encoding: chunkedand noContent-Length. However, the CRT request adapter also synthesized aContent-Lengthfrom the request body publisher's reported length whenever onewas available. This could produce a request carrying both
Content-LengthandTransfer-Encoding: chunked.Per RFC 7230 (section 3.3.2/3.3.3) a sender must not emit
Content-Lengthtogether with
Transfer-Encoding. The underlying CRT layer enforces this andrejects such a request with
AWS_ERROR_HTTP_INVALID_HEADER_FIELD("Both Content-Length and Transfer-Encoding are set. Only one may be used").
This is RFC 7230 compliance hardening. It aligns the CRT client with the Netty
client, which never synthesizes a
Content-Lengthfrom the publisher length fora chunked request. Note: for the operations that actually use request chunked
transfer encoding (unsigned-payload operations) over their normal HTTPS
endpoints, the payload is unsigned and no concrete publisher length is
introduced, so real callers did not hit the conflict; this is defense-in-depth,
not a fix for a runtime hang.
Modifications
CrtRequestAdapter.createAsyncHttpHeaderList(aws-crt-client): no longer addsthe
Content-Lengthheader when the request already carries aTransfer-Encodingheader. Uses the existingHeader.CONTENT_LENGTH/Header.TRANSFER_ENCODINGconstants and the existingfirstMatchingHeaderlookup style. The sync
createHttpHeaderListwas left unchanged: it neversynthesizes
Content-Length(it only copies headers already on the request),so it cannot produce the conflict.
Testing
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License