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
356c353e
Commit
356c353e
authored
Oct 27, 2015
by
Juan Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1882 from ipfs/fix/streaming-output
fix streaming output to flush per write
parents
795e2422
5dc2c7e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
1 deletion
+44
-1
commands/http/handler.go
commands/http/handler.go
+33
-1
test/sharness/t0060-daemon.sh
test/sharness/t0060-daemon.sh
+11
-0
No files found.
commands/http/handler.go
View file @
356c353e
...
@@ -245,13 +245,45 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
...
@@ -245,13 +245,45 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
}
}
w
.
WriteHeader
(
status
)
w
.
WriteHeader
(
status
)
_
,
err
=
io
.
Copy
(
w
,
out
)
err
=
flush
Copy
(
w
,
out
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"err: "
,
err
)
log
.
Error
(
"err: "
,
err
)
w
.
Header
()
.
Set
(
StreamErrHeader
,
sanitizedErrStr
(
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
{
func
sanitizedErrStr
(
err
error
)
string
{
s
:=
err
.
Error
()
s
:=
err
.
Error
()
s
=
strings
.
Split
(
s
,
"
\n
"
)[
0
]
s
=
strings
.
Split
(
s
,
"
\n
"
)[
0
]
...
...
test/sharness/t0060-daemon.sh
View file @
356c353e
...
@@ -109,6 +109,17 @@ test_expect_success "transport should be encrypted" '
...
@@ -109,6 +109,17 @@ test_expect_success "transport should be encrypted" '
test_fsh cat swarmnc
test_fsh cat swarmnc
'
'
test_expect_success
"output from streaming commands works"
'
test_expect_code 28 curl -m 2 http://localhost:5001/api/v0/stats/bw\?poll=true > statsout
'
test_expect_success
"output looks good"
'
grep TotalIn statsout > /dev/null &&
grep TotalOut statsout > /dev/null &&
grep RateIn statsout > /dev/null &&
grep RateOut statsout >/dev/null
'
# end same as in t0010
# end same as in t0010
test_expect_success
"daemon is still running"
'
test_expect_success
"daemon is still running"
'
...
...
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