Skip to content

Commit

Permalink
tar cat should return appropriate headers
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Richard Littauer <richard.littauer@gmail.com>
  • Loading branch information
RichardLitt committed Mar 1, 2016
1 parent cdddf0f commit fc41e1d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions commands/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 42 additions & 0 deletions test/sharness/t0211-tar-headers.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fc41e1d

Please sign in to comment.