Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
1b38d774
Commit
1b38d774
authored
Jan 30, 2016
by
rht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup http client Send
License: MIT Signed-off-by:
rht
<
rhtbot@gmail.com
>
parent
0638ce97
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
36 deletions
+18
-36
http/client.go
http/client.go
+18
-36
No files found.
http/client.go
View file @
1b38d774
...
@@ -38,16 +38,9 @@ type client struct {
...
@@ -38,16 +38,9 @@ type client struct {
}
}
func
NewClient
(
address
string
)
Client
{
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
{
return
&
client
{
serverAddress
:
address
,
serverAddress
:
address
,
httpClient
:
&
http
.
Client
{
httpClient
:
http
.
DefaultClient
,
Transport
:
&
http
.
Transport
{
DisableKeepAlives
:
true
,
},
},
}
}
}
}
...
@@ -101,39 +94,28 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
...
@@ -101,39 +94,28 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
}
}
httpReq
.
Header
.
Set
(
uaHeader
,
config
.
ApiVersion
)
httpReq
.
Header
.
Set
(
uaHeader
,
config
.
ApiVersion
)
ec
:=
make
(
chan
error
,
1
)
rc
:=
make
(
chan
cmds
.
Response
,
1
)
httpReq
.
Cancel
=
req
.
Context
()
.
Done
()
httpReq
.
Cancel
=
req
.
Context
()
.
Done
()
httpReq
.
Close
=
true
go
func
()
{
httpRes
,
err
:=
c
.
httpClient
.
Do
(
httpReq
)
httpRes
,
err
:=
c
.
httpClient
.
Do
(
httpReq
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
ec
<-
err
}
return
}
// using the overridden JSON encoding in request
res
,
err
:=
getResponse
(
httpRes
,
req
)
if
err
!=
nil
{
ec
<-
err
return
}
rc
<-
res
}()
select
{
// using the overridden JSON encoding in request
case
err
:=
<-
ec
:
res
,
err
:=
getResponse
(
httpRes
,
req
)
if
err
!=
nil
{
return
nil
,
err
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
)
{
func
getQuery
(
req
cmds
.
Request
)
(
string
,
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment