net/http/httputil: report ErrBodyReadAfterClose on dumped bodies - #80705
Open
harjothkhara wants to merge 1 commit into
Open
net/http/httputil: report ErrBodyReadAfterClose on dumped bodies#80705harjothkhara wants to merge 1 commit into
harjothkhara wants to merge 1 commit into
Conversation
Contributor
|
This PR (HEAD: 544b342) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/809900. Important tips:
|
DumpRequest, DumpRequestOut and DumpResponse replace the body they are given with an equivalent one read from memory. That replacement was an io.NopCloser, whose Close does nothing, so reading it after Close kept returning data instead of an error. Code that reads a body after closing it is broken, but with these functions in the request path it silently worked, which hid the bug. Return a body that reports http.ErrBodyReadAfterClose once closed, the documented sentinel for this condition, as a real request or response body does. Only the body handed back to the caller is wrapped. drainBody also returns a second reader, used to produce the dump itself and, in DumpRequestOut, to feed the transport; that one stays an io.NopCloser so that net/http continues to recognize it as an in-memory reader and to copy from it without an intermediate buffer. The wrapper tracks closure atomically, since http.Request.Body requires Close to be safe to call concurrently with Read, and forwards WriteTo when the underlying reader supports it, as io.NopCloser does. Fixes golang#77463 Change-Id: Ia9bdfc86edeafb242b8c23aaa83132978c767a9c
harjothkhara
force-pushed
the
fix/httputil-dump-body-close-77463
branch
from
August 4, 2026 03:41
544b342 to
503d7ac
Compare
Contributor
|
This PR (HEAD: 503d7ac) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/809900. Important tips:
|
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.
DumpRequest, DumpRequestOut and DumpResponse replace the body they are
given with an equivalent one read from memory. That replacement was an
io.NopCloser, whose Close does nothing, so reading it after Close kept
returning data instead of an error.
Code that reads a body after closing it is broken, but with these
functions in the request path it silently worked, which hid the bug.
Return a body that reports http.ErrBodyReadAfterClose once closed, the
documented sentinel for this condition, as a real request or response
body does.
Fixes #77463