Skip to content

net/http: RoundTrip unexpectedly changes Request #39533

@neild

Description

@neild

https://go-review.googlesource.com/c/go/+/234894 causes (*http.Transport).RoundTrip to return a different *http.Request in the *http.Response than was passed to it, under some circumstances.

func main() {
        req, err := http.NewRequest("GET", "http://google.com/", bytes.NewBuffer([]byte{0, 1, 2}))
        if err != nil {
                log.Fatal(err)
        }
        resp, err := http.DefaultTransport.RoundTrip(req)
        if err != nil {
                log.Fatal(err)
        }
        fmt.Println(req == resp.Request) // false, where it used to be true.
}

The documentation for (http.Response).Request says, "Request is the request that was sent to obtain this Response." While this doesn't precisely specify that it's the exact *Request passed to RoundTrip, that's probably close enough to consider this an incorrect API change.

Discovered because this breaks code which keeps a map of *http.Requests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.release-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions