Skip to content

chore: use std request clone #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions transport.go
Original file line number Diff line number Diff line change
@@ -47,7 +47,8 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
return nil, err
}

req2 := cloneRequest(req) // per RoundTripper contract
// According to RoundTripper spec, the original request shouldn't be modify.
req2 := req.Clone(req.Context())
token.SetAuthHeader(req2)

// req.Body is assumed to be closed by the base RoundTripper.
@@ -73,17 +74,3 @@ func (t *Transport) base() http.RoundTripper {
}
return http.DefaultTransport
}

// cloneRequest returns a clone of the provided *http.Request.
// The clone is a shallow copy of the struct and its Header map.
func cloneRequest(r *http.Request) *http.Request {
// shallow copy of the struct
r2 := new(http.Request)
*r2 = *r
// deep copy of the Header
r2.Header = make(http.Header, len(r.Header))
for k, s := range r.Header {
r2.Header[k] = append([]string(nil), s...)
}
return r2
}