Commit 1b38d774 authored by rht's avatar rht

Cleanup http client Send

License: MIT
Signed-off-by: default avatarrht <rhtbot@gmail.com>
parent 0638ce97
......@@ -38,16 +38,9 @@ type client struct {
}
func NewClient(address string) Client {
// We cannot use the default transport because of a bug in go's connection reuse
// code. It causes random failures in the connection including io.EOF and connection
// refused on 'client.Do'
return &client{
serverAddress: address,
httpClient: &http.Client{
Transport: &http.Transport{
DisableKeepAlives: true,
},
},
httpClient: http.DefaultClient,
}
}
......@@ -101,39 +94,28 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
}
httpReq.Header.Set(uaHeader, config.ApiVersion)
ec := make(chan error, 1)
rc := make(chan cmds.Response, 1)
httpReq.Cancel = req.Context().Done()
httpReq.Close = true
go func() {
httpRes, err := c.httpClient.Do(httpReq)
if err != nil {
ec <- err
return
}
// using the overridden JSON encoding in request
res, err := getResponse(httpRes, req)
if err != nil {
ec <- err
return
}
rc <- res
}()
httpRes, err := c.httpClient.Do(httpReq)
if err != nil {
return nil, err
}
select {
case err := <-ec:
// using the overridden JSON encoding in request
res, err := getResponse(httpRes, req)
if err != nil {
return nil, err
case res := <-rc:
if found && len(previousUserProvidedEncoding) > 0 {
// reset to user provided encoding after sending request
// NB: if user has provided an encoding but it is the empty string,
// still leave it as JSON.
req.SetOption(cmds.EncShort, previousUserProvidedEncoding)
}
return res, nil
}
if found && len(previousUserProvidedEncoding) > 0 {
// reset to user provided encoding after sending request
// NB: if user has provided an encoding but it is the empty string,
// still leave it as JSON.
req.SetOption(cmds.EncShort, previousUserProvidedEncoding)
}
return res, nil
}
func getQuery(req cmds.Request) (string, error) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment