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
Commits
cf1e770e
Commit
cf1e770e
authored
Dec 17, 2014
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/http: Client: decode chunked streaming output
parent
c3c0b248
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
commands/http/client.go
commands/http/client.go
+23
-0
No files found.
commands/http/client.go
View file @
cf1e770e
...
@@ -137,8 +137,31 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
...
@@ -137,8 +137,31 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
contentType
=
strings
.
Split
(
contentType
,
";"
)[
0
]
contentType
=
strings
.
Split
(
contentType
,
";"
)[
0
]
if
len
(
httpRes
.
Header
.
Get
(
streamHeader
))
>
0
{
if
len
(
httpRes
.
Header
.
Get
(
streamHeader
))
>
0
{
// if output is a stream, we can just use the body reader
res
.
SetOutput
(
httpRes
.
Body
)
res
.
SetOutput
(
httpRes
.
Body
)
return
res
,
nil
return
res
,
nil
}
else
if
len
(
httpRes
.
Header
.
Get
(
channelHeader
))
>
0
{
// if output is coming from a channel, decode each chunk
outChan
:=
make
(
chan
interface
{})
go
func
()
{
dec
:=
json
.
NewDecoder
(
httpRes
.
Body
)
v
:=
req
.
Command
()
.
Type
for
{
err
:=
dec
.
Decode
(
&
v
)
if
err
!=
nil
{
if
err
!=
io
.
EOF
{
fmt
.
Println
(
err
.
Error
())
}
return
}
outChan
<-
v
}
}()
res
.
SetOutput
(
outChan
)
return
res
,
nil
}
}
dec
:=
json
.
NewDecoder
(
httpRes
.
Body
)
dec
:=
json
.
NewDecoder
(
httpRes
.
Body
)
...
...
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