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
4470826f
Commit
4470826f
authored
Oct 21, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix streaming output to flush per write
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
795e2422
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
1 deletion
+33
-1
commands/http/handler.go
commands/http/handler.go
+33
-1
No files found.
commands/http/handler.go
View file @
4470826f
...
...
@@ -245,13 +245,45 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
}
w
.
WriteHeader
(
status
)
_
,
err
=
io
.
Copy
(
w
,
out
)
err
=
flush
Copy
(
w
,
out
)
if
err
!=
nil
{
log
.
Error
(
"err: "
,
err
)
w
.
Header
()
.
Set
(
StreamErrHeader
,
sanitizedErrStr
(
err
))
}
}
func
flushCopy
(
w
io
.
Writer
,
r
io
.
Reader
)
error
{
buf
:=
make
([]
byte
,
4096
)
f
,
ok
:=
w
.
(
http
.
Flusher
)
if
!
ok
{
_
,
err
:=
io
.
Copy
(
w
,
r
)
return
err
}
for
{
n
,
err
:=
r
.
Read
(
buf
)
switch
err
{
case
io
.
EOF
:
return
nil
case
nil
:
// continue
default
:
return
err
}
nw
,
err
:=
w
.
Write
(
buf
[
:
n
])
if
err
!=
nil
{
return
err
}
if
nw
!=
n
{
return
fmt
.
Errorf
(
"http write failed to write full amount: %d != %d"
,
nw
,
n
)
}
f
.
Flush
()
}
return
nil
}
func
sanitizedErrStr
(
err
error
)
string
{
s
:=
err
.
Error
()
s
=
strings
.
Split
(
s
,
"
\n
"
)[
0
]
...
...
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