@@ -6,7 +6,7 @@ package oauth2
6
6
7
7
import (
8
8
"errors"
9
- "io "
9
+ "log "
10
10
"net/http"
11
11
"sync"
12
12
)
@@ -25,9 +25,6 @@ type Transport struct {
25
25
// Base is the base RoundTripper used to make HTTP requests.
26
26
// If nil, http.DefaultTransport is used.
27
27
Base http.RoundTripper
28
-
29
- mu sync.Mutex // guards modReq
30
- modReq map [* http.Request ]* http.Request // original -> modified
31
28
}
32
29
33
30
// RoundTrip authorizes and authenticates the request with an
@@ -52,35 +49,22 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
52
49
53
50
req2 := cloneRequest (req ) // per RoundTripper contract
54
51
token .SetAuthHeader (req2 )
55
- t .setModReq (req , req2 )
56
- res , err := t .base ().RoundTrip (req2 )
57
52
58
- // req.Body is assumed to have been closed by the base RoundTripper.
53
+ // req.Body is assumed to be closed by the base RoundTripper.
59
54
reqBodyClosed = true
60
-
61
- if err != nil {
62
- t .setModReq (req , nil )
63
- return nil , err
64
- }
65
- res .Body = & onEOFReader {
66
- rc : res .Body ,
67
- fn : func () { t .setModReq (req , nil ) },
68
- }
69
- return res , nil
55
+ return t .base ().RoundTrip (req2 )
70
56
}
71
57
72
- // CancelRequest cancels an in-flight request by closing its connection.
58
+ var cancelOnce sync.Once
59
+
60
+ // CancelRequest does nothing. It used to be a legacy cancellation mechanism
61
+ // but now only it only logs on first use to warn that it's deprecated.
62
+ //
63
+ // Deprecated: use contexts for cancellation instead.
73
64
func (t * Transport ) CancelRequest (req * http.Request ) {
74
- type canceler interface {
75
- CancelRequest (* http.Request )
76
- }
77
- if cr , ok := t .base ().(canceler ); ok {
78
- t .mu .Lock ()
79
- modReq := t .modReq [req ]
80
- delete (t .modReq , req )
81
- t .mu .Unlock ()
82
- cr .CancelRequest (modReq )
83
- }
65
+ cancelOnce .Do (func () {
66
+ log .Printf ("deprecated: golang.org/x/oauth2: Transport.CancelRequest no longer does anything; use contexts" )
67
+ })
84
68
}
85
69
86
70
func (t * Transport ) base () http.RoundTripper {
@@ -90,19 +74,6 @@ func (t *Transport) base() http.RoundTripper {
90
74
return http .DefaultTransport
91
75
}
92
76
93
- func (t * Transport ) setModReq (orig , mod * http.Request ) {
94
- t .mu .Lock ()
95
- defer t .mu .Unlock ()
96
- if t .modReq == nil {
97
- t .modReq = make (map [* http.Request ]* http.Request )
98
- }
99
- if mod == nil {
100
- delete (t .modReq , orig )
101
- } else {
102
- t .modReq [orig ] = mod
103
- }
104
- }
105
-
106
77
// cloneRequest returns a clone of the provided *http.Request.
107
78
// The clone is a shallow copy of the struct and its Header map.
108
79
func cloneRequest (r * http.Request ) * http.Request {
@@ -116,29 +87,3 @@ func cloneRequest(r *http.Request) *http.Request {
116
87
}
117
88
return r2
118
89
}
119
-
120
- type onEOFReader struct {
121
- rc io.ReadCloser
122
- fn func ()
123
- }
124
-
125
- func (r * onEOFReader ) Read (p []byte ) (n int , err error ) {
126
- n , err = r .rc .Read (p )
127
- if err == io .EOF {
128
- r .runFunc ()
129
- }
130
- return
131
- }
132
-
133
- func (r * onEOFReader ) Close () error {
134
- err := r .rc .Close ()
135
- r .runFunc ()
136
- return err
137
- }
138
-
139
- func (r * onEOFReader ) runFunc () {
140
- if fn := r .fn ; fn != nil {
141
- fn ()
142
- r .fn = nil
143
- }
144
- }
0 commit comments