fix: clear requestRaw and requestHostname on Request.Reset()#1
Open
steps-re wants to merge 1 commit into
Open
Conversation
Request objects are recycled through the request pool (ReleaseRequest -> Reset -> pool). Reset() did not clear the raw-request fields, so a Request reused from the pool retained a previously set raw request. Because Write() emits requestRaw verbatim when it is non-empty, a recycled Request would send the stale raw bytes instead of the newly built request. Clear both fields in resetSkipHeader() so all Reset paths (client pool and server keep-alive reuse) start from a clean state. Adds a regression test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Mike German <mike@stepsventures.com>
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.
Summary
Request.Reset()does not clear the two fields this fork adds for raw requests, so aRequestreused from thesync.Poolcan send a stale raw request set by a previous user.Details
requestRawandrequestHostnameimplement this fork's core "send a raw HTTP request" feature.Request.Reset()(viaresetSkipHeader()) clears body/uri/headers/postArgs but never these two fields. SinceReleaseRequest()callsReset()and returns the object to a pool, andRequest.Write()emitsrequestRawverbatim whenever it is non-empty, a recycledRequestsilently writes the previous user's raw bytes (old method/path/host/body) to the wire. For a request-forging library this is a correctness and safety bug.Fix
Clear both fields in
resetSkipHeader()so every reset path (client pool reuse and server keep-alive reuse) starts clean.Verification
go build ./...clean (Go 1.23).rawrequest_reset_test.go: sets a raw request, callsReset(), builds a normal request on the recycled object, and asserts the stale bytes are not written. Fails without the fix (Reset did not clear requestRaw), passes with it.go test -shortsuite passes, no regressions.