Skip to content

Commit b08228c

Browse files
committed
oauth2: use request.Clone() instead of a custom clone implementation
Also updates #457
1 parent cfe200d commit b08228c

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

transport.go

+1-15
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
4747
return nil, err
4848
}
4949

50-
req2 := cloneRequest(req) // per RoundTripper contract
50+
req2 := req.Clone(req.Context()) // per RoundTripper contract
5151
token.SetAuthHeader(req2)
5252

5353
// req.Body is assumed to be closed by the base RoundTripper.
@@ -73,17 +73,3 @@ func (t *Transport) base() http.RoundTripper {
7373
}
7474
return http.DefaultTransport
7575
}
76-
77-
// cloneRequest returns a clone of the provided *http.Request.
78-
// The clone is a shallow copy of the struct and its Header map.
79-
func cloneRequest(r *http.Request) *http.Request {
80-
// shallow copy of the struct
81-
r2 := new(http.Request)
82-
*r2 = *r
83-
// deep copy of the Header
84-
r2.Header = make(http.Header, len(r.Header))
85-
for k, s := range r.Header {
86-
r2.Header[k] = append([]string(nil), s...)
87-
}
88-
return r2
89-
}

0 commit comments

Comments
 (0)