mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 09:20:02 +08:00
Merge pull request #1732 from WeMeetAgain/fix-http-api-content-type
remove hard-coded json content-type for streaming http output
This commit is contained in:
@ -224,13 +224,8 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
|
|||||||
_, isChan = res.Output().(<-chan interface{})
|
_, isChan = res.Output().(<-chan interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
streamChans, _, _ := req.Option("stream-channels").Bool()
|
|
||||||
if isChan {
|
if isChan {
|
||||||
h.Set(channelHeader, "1")
|
h.Set(channelHeader, "1")
|
||||||
if streamChans {
|
|
||||||
// streaming output from a channel will always be json objects
|
|
||||||
mime = applicationJson
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if mime != "" {
|
if mime != "" {
|
||||||
|
61
test/sharness/t0230-channel-streaming-http-content-type.sh
Executable file
61
test/sharness/t0230-channel-streaming-http-content-type.sh
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2015 Cayman Nava
|
||||||
|
# MIT Licensed; see the LICENSE file in this repository.
|
||||||
|
#
|
||||||
|
|
||||||
|
test_description="Test Content-Type for channel-streaming commands"
|
||||||
|
|
||||||
|
. lib/test-lib.sh
|
||||||
|
|
||||||
|
test_init_ipfs
|
||||||
|
|
||||||
|
test_ls_cmd() {
|
||||||
|
|
||||||
|
test_expect_success "Text encoded channel-streaming command succeeds" '
|
||||||
|
mkdir -p testdir &&
|
||||||
|
echo "hello test" >testdir/test.txt &&
|
||||||
|
ipfs add -r testdir &&
|
||||||
|
curl -i "http://localhost:$PORT_API/api/v0/refs?arg=QmTcJAn3JP8ZMAKS6WS75q8sbTyojWKbxcUHgLYGWur4Ym&stream-channels=true&encoding=text" >actual_output
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "Text encoded channel-streaming command output looks good" '
|
||||||
|
printf "HTTP/1.1 200 OK\r\n" >expected_output &&
|
||||||
|
printf "Content-Type: text/plain\r\n" >>expected_output &&
|
||||||
|
printf "Transfer-Encoding: chunked\r\n" >>expected_output &&
|
||||||
|
printf "X-Chunked-Output: 1\r\n" >>expected_output &&
|
||||||
|
printf "\r\n" >>expected_output &&
|
||||||
|
echo QmRmPLc1FsPAn8F8F9DQDEYADNX5ER2sgqiokEvqnYknVW >>expected_output &&
|
||||||
|
test_cmp expected_output actual_output
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "JSON encoded channel-streaming command succeeds" '
|
||||||
|
mkdir -p testdir &&
|
||||||
|
echo "hello test" >testdir/test.txt &&
|
||||||
|
ipfs add -r testdir &&
|
||||||
|
curl -i "http://localhost:$PORT_API/api/v0/refs?arg=QmTcJAn3JP8ZMAKS6WS75q8sbTyojWKbxcUHgLYGWur4Ym&stream-channels=true&encoding=json" >actual_output
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "JSON encoded channel-streaming command output looks good" '
|
||||||
|
printf "HTTP/1.1 200 OK\r\n" >expected_output &&
|
||||||
|
printf "Content-Type: application/json\r\n" >>expected_output &&
|
||||||
|
printf "Transfer-Encoding: chunked\r\n" >>expected_output &&
|
||||||
|
printf "X-Chunked-Output: 1\r\n" >>expected_output &&
|
||||||
|
printf "\r\n" >>expected_output &&
|
||||||
|
cat <<-\EOF >>expected_output &&
|
||||||
|
{
|
||||||
|
"Ref": "QmRmPLc1FsPAn8F8F9DQDEYADNX5ER2sgqiokEvqnYknVW",
|
||||||
|
"Err": ""
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
perl -pi -e '"'"'chomp if eof'"'"' expected_output &&
|
||||||
|
test_cmp expected_output actual_output
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
# should work online (only)
|
||||||
|
test_launch_ipfs_daemon
|
||||||
|
test_ls_cmd
|
||||||
|
test_kill_ipfs_daemon
|
||||||
|
|
||||||
|
test_done
|
Reference in New Issue
Block a user