Skip to content

Commit

Permalink
chore: use std request clone
Browse files Browse the repository at this point in the history
  • Loading branch information
gastonqiu committed Jun 30, 2023
1 parent 989acb1 commit cb1e28c
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
return nil, err
}

req2 := cloneRequest(req) // per RoundTripper contract
req2 := req.Clone(req.Context())
token.SetAuthHeader(req2)

// req.Body is assumed to be closed by the base RoundTripper.
Expand All @@ -73,17 +73,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
}

0 comments on commit cb1e28c

Please sign in to comment.