@@ -30,7 +30,7 @@ type Client interface {
30
30
31
31
type client struct {
32
32
serverAddress string
33
- httpClient http.Client
33
+ httpClient * http.Client
34
34
}
35
35
36
36
func NewClient (address string ) Client {
@@ -39,7 +39,7 @@ func NewClient(address string) Client {
39
39
// refused on 'client.Do'
40
40
return & client {
41
41
serverAddress : address ,
42
- httpClient : http.Client {
42
+ httpClient : & http.Client {
43
43
Transport : & http.Transport {
44
44
DisableKeepAlives : true ,
45
45
},
@@ -105,7 +105,7 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
105
105
106
106
ec := make (chan error , 1 )
107
107
rc := make (chan cmds.Response , 1 )
108
- dc : = req .Context ().Done ()
108
+ httpReq . Cancel = req .Context ().Done ()
109
109
110
110
go func () {
111
111
httpRes , err := c .httpClient .Do (httpReq )
@@ -124,24 +124,17 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
124
124
rc <- res
125
125
}()
126
126
127
- for {
128
- select {
129
- case <- dc :
130
- log .Debug ("Context cancelled, cancelling HTTP request..." )
131
- tr := http .DefaultTransport .(* http.Transport )
132
- tr .CancelRequest (httpReq )
133
- dc = nil // Wait for ec or rc
134
- case err := <- ec :
135
- return nil , err
136
- case res := <- rc :
137
- if found && len (previousUserProvidedEncoding ) > 0 {
138
- // reset to user provided encoding after sending request
139
- // NB: if user has provided an encoding but it is the empty string,
140
- // still leave it as JSON.
141
- req .SetOption (cmds .EncShort , previousUserProvidedEncoding )
142
- }
143
- return res , nil
127
+ select {
128
+ case err := <- ec :
129
+ return nil , err
130
+ case res := <- rc :
131
+ if found && len (previousUserProvidedEncoding ) > 0 {
132
+ // reset to user provided encoding after sending request
133
+ // NB: if user has provided an encoding but it is the empty string,
134
+ // still leave it as JSON.
135
+ req .SetOption (cmds .EncShort , previousUserProvidedEncoding )
144
136
}
137
+ return res , nil
145
138
}
146
139
}
147
140
0 commit comments