Cleanup http client Send
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
rht committed
Jan 30, 2016 at 10:22 UTC
72e98deb93355ddfcc179b03cc1d1d5d737ca071
1 file changed
+18
-36
commands/http/client.go
+18
-36
@@ -38,16 +38,9 @@ type client struct {
38
}
39
40
func NewClient(address string) Client {
41
- // We cannot use the default transport because of a bug in go's connection reuse
42
- // code. It causes random failures in the connection including io.EOF and connection
43
- // refused on 'client.Do'
41
return &client{
42
serverAddress: address,
46
- httpClient: &http.Client{
47
- Transport: &http.Transport{
48
- DisableKeepAlives: true,
49
- },
50
- },
43
+ httpClient: http.DefaultClient,
44
}
45
}
46
@@ -101,39 +94,28 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
94
}
95
httpReq.Header.Set(uaHeader, config.ApiVersion)
96
104
- ec := make(chan error, 1)
105
- rc := make(chan cmds.Response, 1)
97
httpReq.Cancel = req.Context().Done()
98
+ httpReq.Close = true
99
108
- go func() {
109
- httpRes, err := c.httpClient.Do(httpReq)
110
- if err != nil {
111
- ec <- err
112
- return
113
- }
114
-
115
- // using the overridden JSON encoding in request
116
- res, err := getResponse(httpRes, req)
117
- if err != nil {
118
- ec <- err
119
- return
120
- }
121
-
122
- rc <- res
123
- }()
100
+ httpRes, err := c.httpClient.Do(httpReq)
101
+ if err != nil {
102
+ return nil, err
103
+ }
104
125
- select {
126
- case err := <-ec:
105
+ // using the overridden JSON encoding in request
106
+ res, err := getResponse(httpRes, req)
107
+ if err != nil {
108
return nil, err
128
- case res := <-rc:
129
- if found && len(previousUserProvidedEncoding) > 0 {
130
- // reset to user provided encoding after sending request
131
- // NB: if user has provided an encoding but it is the empty string,
132
- // still leave it as JSON.
133
- req.SetOption(cmds.EncShort, previousUserProvidedEncoding)
134
- }
135
- return res, nil
109
}
110
+
111
+ if found && len(previousUserProvidedEncoding) > 0 {
112
+ // reset to user provided encoding after sending request
113
+ // NB: if user has provided an encoding but it is the empty string,
114
+ // still leave it as JSON.
115
+ req.SetOption(cmds.EncShort, previousUserProvidedEncoding)
116
+ }
117
+
118
+ return res, nil
119
}
120
121
func getQuery(req cmds.Request) (string, error) {