From fc41e1d8fcab376258e5e9caa960490ededb2b2b Mon Sep 17 00:00:00 2001 From: Richard Littauer Date: Tue, 1 Mar 2016 18:07:55 -0500 Subject: [PATCH] `tar cat` should return appropriate headers License: MIT Signed-off-by: Richard Littauer --- commands/http/handler.go | 4 +++ test/sharness/t0211-tar-headers.sh | 42 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 test/sharness/t0211-tar-headers.sh diff --git a/commands/http/handler.go b/commands/http/handler.go index 9ac6d4a4a43a..c5b916f91c51 100644 --- a/commands/http/handler.go +++ b/commands/http/handler.go @@ -262,6 +262,10 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req h.Set(channelHeader, "1") } + if len(res.Request().Path()) == 2 && res.Request().Path()[0] == "tar" { + mime = "application/x-tar" + } + // catch-all, set to text as default if mime == "" { mime = "text/plain" diff --git a/test/sharness/t0211-tar-headers.sh b/test/sharness/t0211-tar-headers.sh new file mode 100755 index 000000000000..8c0898ae68e6 --- /dev/null +++ b/test/sharness/t0211-tar-headers.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +test_description="Test tar cat headers" + +test_tar_cat_headers() { + mkdir foo && + random 10000 > foo/a && + random 12345 > foo/b && + mkdir foo/bar && + random 5432 > foo/bar/baz && + ln -s ../a foo/bar/link && + echo "exit" > foo/script && + chmod +x foo/script + tar cf files.tar foo/ + TAR_HASH=$(ipfs tar add files.tar) + mkdir output && + ipfs tar cat $TAR_HASH > output/out.tar +} + +. lib/test-lib.sh + +test_init_ipfs +test_tar_cat_headers +test_launch_ipfs_daemon + +gwport=$GWAY_PORT +apiport=$API_PORT + +# Gateway + +# HTTP GET Request +test_expect_success "GET to Gateway succeeds" ' + curl -svX GET "http://127.0.0.1:$gwport/api/v0/tar/cat?arg=$TAR_HASH" 2>curl_output +' +# GET Response from Gateway should contain correct content type +test_expect_success "GET response for Gateway resource looks good" ' + grep "application:x-tar" curl_output +' + +test_kill_ipfs_daemon + +test_done