Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a7e100

Browse files
committedNov 24, 2015
ipfs get: set correct content-type on resp
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
1 parent b9e8c00 commit 1a7e100

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed
 

‎commands/http/handler.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const (
6161
var mimeTypes = map[string]string{
6262
cmds.JSON: "application/json",
6363
cmds.XML: "application/xml",
64+
cmds.Tar: "application/x-tar",
65+
cmds.Gzip: "application/gzip", // http://tools.ietf.org/html/rfc6713
6466
cmds.Text: "text/plain",
6567
}
6668

@@ -232,7 +234,9 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
232234
if _, ok := res.Output().(io.Reader); ok {
233235
// set streams output type to text to avoid issues with browsers rendering
234236
// html pages on priveleged api ports
235-
mime = "text/plain"
237+
if mime != mimeTypes[cmds.Tar] && mime != mimeTypes[cmds.Gzip] {
238+
mime = mimeTypes[cmds.Text]
239+
}
236240
h.Set(streamHeader, "1")
237241
}
238242

‎commands/response.go

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type EncodingType string
3838
const (
3939
JSON = "json"
4040
XML = "xml"
41+
Tar = "tar"
42+
Gzip = "gzip"
4143
Text = "text"
4244
// TODO: support more encoding types
4345
)

‎core/commands/get.go

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ may also specify the level of compression by specifying '-l=<1-9>'.
6969
return
7070
}
7171

72+
// set the correct mime type for tar stream
73+
req.SetOption(cmds.EncShort, cmds.Tar)
74+
if cmplvl != gzip.NoCompression {
75+
req.SetOption(cmds.EncShort, cmds.Gzip)
76+
}
77+
7278
archive, _, _ := req.Option("archive").Bool()
7379
reader, err := uarchive.DagArchive(ctx, dn, p.String(), node.DAG, archive, cmplvl)
7480
if err != nil {

‎test/sharness/t0090-get.sh

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ test_get_cmd
119119
# should work online
120120
test_launch_ipfs_daemon
121121
test_get_cmd
122+
test_expect_success "ipfs get response has the correct content-type" '
123+
curl -I "http://localhost:$PORT_API/api/v0/get?arg=$HASH" | grep "^Content-Type: application/x-tar"
124+
'
122125
test_kill_ipfs_daemon
123126

124127
test_done

0 commit comments

Comments
 (0)
Please sign in to comment.