Skip to content

fix: body truncation caused by async logging - #765

Merged
dwisiswant0 merged 2 commits into
devfrom
dwisiswant0/fix/body-truncation-caused-by-async-logging
Sep 14, 2026
Merged

dwisiswant0 merged 2 commits into
devfrom
dwisiswant0/fix/body-truncation-caused-by-async-logging

Conversation

@dwisiswant0

Copy link
Copy Markdown
Member

Proposed changes

Capture HTTP bodies as forwarding reads them and give the logger
independent readers. This prevents logging from consuming bytes needed
by the upstream server or downstream client.
response processing could therefore read, replace, or close bodies
while the transport was using them. Verbose request logging also
consumed the body without restoring it. Setting ContentLength to -1
changed framing but did not resolve the shared reader ownership.

Add a body capture wrapper that records forwarding reads and publishes
immutable data when capture completes. Preserve read errors and forward
Close to the original body without holding the capture lock, allowing
Close to unblock an active Read. Retain the existing 4096-byte response
log limit without limiting the forwarded response, and leave upgraded
connections unwrapped.

Queue metadata snapshots and capture handles. Retain the request
capture in its context so response logs can include the request body
after the transport consumes it. Use completed trailer copies instead
of cloning live request trailers during an early response. Restore the
private request body after verbose inspection for subsequent writers.

Keep HAR processing on the original request pointer for Martian context
lookup, before publishing the asynchronous transaction. Preserve its
existing synchronous behavior and log-and-continue error handling.

Preserve incoming ContentLength instead of forcing unknown length.
When rebuilding a request after match-and-replace, copy ContentLength,
TransferEncoding, and Trailer from the parsed request and clear GetBody
so it cannot replay the old body.

Fixes #749

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Capture HTTP bodies as forwarding reads them and give the logger
independent readers. This prevents logging from consuming bytes needed
by the upstream server or downstream client.
response processing could therefore read, replace, or close bodies
while the transport was using them. Verbose request logging also
consumed the body without restoring it. Setting ContentLength to -1
changed framing but did not resolve the shared reader ownership.

Add a body capture wrapper that records forwarding reads and publishes
immutable data when capture completes. Preserve read errors and forward
Close to the original body without holding the capture lock, allowing
Close to unblock an active Read. Retain the existing 4096-byte response
log limit without limiting the forwarded response, and leave upgraded
connections unwrapped.

Queue metadata snapshots and capture handles. Retain the request
capture in its context so response logs can include the request body
after the transport consumes it. Use completed trailer copies instead
of cloning live request trailers during an early response. Restore the
private request body after verbose inspection for subsequent writers.

Keep HAR processing on the original request pointer for Martian context
lookup, before publishing the asynchronous transaction. Preserve its
existing synchronous behavior and log-and-continue error handling.

Preserve incoming ContentLength instead of forcing unknown length.
When rebuilding a request after match-and-replace, copy ContentLength,
TransferEncoding, and Trailer from the parsed request and clear GetBody
so it cannot replay the old body.

Fixes #749

Signed-off-by: Dwi Siswanto <git@dw1.io>
@dwisiswant0
dwisiswant0 merged commit 0cefd1a into dev Sep 14, 2026
8 checks passed
@dwisiswant0
dwisiswant0 deleted the dwisiswant0/fix/body-truncation-caused-by-async-logging branch September 14, 2026 01:12
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.

2 participants