Skip to content

Commit 8b2a8b4

Browse files
committed
api: correctly set the content type for object get --encoding=protobuf
It used to default to `application/json` but is now correctly set to `application/protobuf`. fixes #2469 License: MIT Signed-off-by: Steven Allen <[email protected]>
1 parent 87cf84e commit 8b2a8b4

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

commands/http/handler.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ const (
6565
)
6666

6767
var mimeTypes = map[string]string{
68-
cmds.JSON: "application/json",
69-
cmds.XML: "application/xml",
70-
cmds.Text: "text/plain",
68+
cmds.Protobuf: "application/protobuf",
69+
cmds.JSON: "application/json",
70+
cmds.XML: "application/xml",
71+
cmds.Text: "text/plain",
7172
}
7273

7374
type ServerConfig struct {

commands/response.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ type EncodingType string
3636

3737
// Supported EncodingType constants.
3838
const (
39-
JSON = "json"
40-
XML = "xml"
41-
Text = "text"
39+
JSON = "json"
40+
XML = "xml"
41+
Protobuf = "protobuf"
42+
Text = "text"
4243
// TODO: support more encoding types
4344
)
4445

core/commands/object/object.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ This command outputs data in the following encodings:
222222
},
223223
Type: Node{},
224224
Marshalers: cmds.MarshalerMap{
225-
cmds.EncodingType("protobuf"): func(res cmds.Response) (io.Reader, error) {
225+
cmds.Protobuf: func(res cmds.Response) (io.Reader, error) {
226226
node := res.Output().(*Node)
227227
object, err := deserializeNode(node)
228228
if err != nil {

test/sharness/t0051-object.sh

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ test_object_cmd() {
4343
ipfs object get $HASH >actual_getOut
4444
'
4545

46+
test_expect_success "'ipfs object get --encoding=protobuf' returns the correct content type" '
47+
curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=protobuf" | grep -q "^Content-Type: application/protobuf"
48+
'
49+
50+
test_expect_success "'ipfs object get --encoding=json' returns the correct content type" '
51+
curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=json" | grep -q "^Content-Type: application/json"
52+
'
53+
54+
test_expect_success "'ipfs object get --encoding=text' returns the correct content type" '
55+
curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=text" | grep -q "^Content-Type: text/plain"
56+
'
57+
58+
test_expect_success "'ipfs object get --encoding=xml' returns the correct content type" '
59+
curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=xml" | grep -q "^Content-Type: application/xml"
60+
'
61+
4662
test_expect_success "'ipfs object get' output looks good" '
4763
test_cmp ../t0051-object-data/expected_getOut actual_getOut
4864
'

0 commit comments

Comments
 (0)