Skip to content

Preserve contentLength for InMemoryPublisher#7141

Open
davidh44 wants to merge 4 commits into
masterfrom
hdavidh/inMemoryPublisher-preserve-contentLength
Open

Preserve contentLength for InMemoryPublisher#7141
davidh44 wants to merge 4 commits into
masterfrom
hdavidh/inMemoryPublisher-preserve-contentLength

Conversation

@davidh44

Copy link
Copy Markdown
Contributor

Motivation and Context

Follow up to #7129

After fixing the InMemoryPublisher deadlock, InMemoryPublisher still reports no contentLength() because it only implements bare Publisher<ByteBuffer>. This means the CRT HTTP client receives getLength()=0 ("unknown length"). Additionally, FlexibleChecksummer has a theoretical race condition where checksum headers could be set after signing due to a detached thenRun side-effect.

When InMemoryPublisher correctly reports its content length, a latent bug in MakeAsyncHttpRequestStage is exposed: it adds Content-Length even when Transfer-Encoding: chunked is already present, violating RFC 7230 §3.3.2.

These are not customer-facing bugs today: CRT handles getLength()=0 correctly and the race condition only manifests with async body sources. This PR is defensive hardening to prevent future issues.

Modifications

Checksum computation (http-auth-aws)

  • FlexibleChecksummer — Replace detached thenRun with thenApply to guarantee checksum headers are set before signing proceeds. Theoretical race condition fix — prevents issues if the body source delivers asynchronously.
  • ChecksumSubscriber — Compute total buffered bytes in onComplete() and pass to InMemoryPublisher.
  • InMemoryPublisher — Implement SdkHttpContentPublisher to report contentLength().

Signing (sdk-core)

  • AsyncSigningStage — Preserve contentLength() when wrapping SdkHttpContentPublisher payload into AsyncRequestBody, instead of always using fromPublisher() which loses it.

HTTP request construction (sdk-core)

  • MakeAsyncHttpRequestStage — Don't set Content-Length if Transfer-Encoding is already present. These are mutually exclusive per RFC 7230 §3.3.2.

Testing

Added unit tests, updated TCK test

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@davidh44 davidh44 requested a review from a team as a code owner July 13, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant