Skip to content

Keep a caller-supplied ContentLength for *io.PipeReader bodies - #704

Open
afreidah wants to merge 1 commit into
aws:mainfrom
afreidah:fix/pipereader-content-length
Open

afreidah wants to merge 1 commit into
aws:mainfrom
afreidah:fix/pipereader-content-length

Conversation

@afreidah

@afreidah afreidah commented Sep 2, 2026

Copy link
Copy Markdown

Issue #, if available: #703

Description of changes:

Request.Build overwrote ContentLength with -1 whenever the stream was an
*io.PipeReader, discarding a length the caller had already set. Signing runs
before Build, so SigV4 had put content-length in SignedHeaders by then.
The request went out chunked with no Content-Length header, and no backend
could validate it: 411 where the header is required, 403 SignatureDoesNotMatch
where only the signature is checked.

Build now fills in ContentLength only when it is unknown. A pipe with no
known length still falls back to chunked encoding, so nothing changes for
callers who do not supply one.

Tests:

  • Three cases added to TestRequestBuild_contentLength for a pipe with a known
    length, with 0, and with -1.
  • TestRequestBuild_pipeReaderFraming sends a built request to an httptest
    server and asserts the framing that actually arrives, rather than the field
    alone.

Both fail on main and pass with this change. make unit-race and gorelease
are clean.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Build overwrote ContentLength with -1 for a pipe even when the caller had
set it. Signing runs before Build, so SigV4 had already put content-length
in SignedHeaders; the request then went out chunked with no Content-Length
header and no backend could validate it.
@afreidah
afreidah requested review from a team as code owners September 2, 2026 08:37
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