From d6cc942c3485ea1a998d54d7f9b2e0ef05d7de33 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 30 Mar 2016 11:32:23 -0400 Subject: [PATCH] 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 --- commands/http/handler.go | 7 ++++--- commands/response.go | 7 ++++--- core/commands/object/object.go | 2 +- test/sharness/t0051-object.sh | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/commands/http/handler.go b/commands/http/handler.go index 82850764ff3e..d6e988887787 100644 --- a/commands/http/handler.go +++ b/commands/http/handler.go @@ -65,9 +65,10 @@ const ( ) var mimeTypes = map[string]string{ - cmds.JSON: "application/json", - cmds.XML: "application/xml", - cmds.Text: "text/plain", + cmds.Protobuf: "application/protobuf", + cmds.JSON: "application/json", + cmds.XML: "application/xml", + cmds.Text: "text/plain", } type ServerConfig struct { diff --git a/commands/response.go b/commands/response.go index 577b86a8b4f8..913b684bdaeb 100644 --- a/commands/response.go +++ b/commands/response.go @@ -36,9 +36,10 @@ type EncodingType string // Supported EncodingType constants. const ( - JSON = "json" - XML = "xml" - Text = "text" + JSON = "json" + XML = "xml" + Protobuf = "protobuf" + Text = "text" // TODO: support more encoding types ) diff --git a/core/commands/object/object.go b/core/commands/object/object.go index f16ef7160059..240d16428c35 100644 --- a/core/commands/object/object.go +++ b/core/commands/object/object.go @@ -222,7 +222,7 @@ This command outputs data in the following encodings: }, Type: Node{}, Marshalers: cmds.MarshalerMap{ - cmds.EncodingType("protobuf"): func(res cmds.Response) (io.Reader, error) { + cmds.Protobuf: func(res cmds.Response) (io.Reader, error) { node := res.Output().(*Node) object, err := deserializeNode(node) if err != nil { diff --git a/test/sharness/t0051-object.sh b/test/sharness/t0051-object.sh index 00bdff0e1343..e6e74cd2056b 100755 --- a/test/sharness/t0051-object.sh +++ b/test/sharness/t0051-object.sh @@ -43,6 +43,22 @@ test_object_cmd() { ipfs object get $HASH >actual_getOut ' + test_expect_success "'ipfs object get --encoding=protobuf' returns the correct content type" ' + curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=protobuf" | grep -q "^Content-Type:\s*application/protobuf" + ' + + test_expect_success "'ipfs object get --encoding=json' returns the correct content type" ' + curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=json" | grep -q "^Content-Type:\s*application/json" + ' + + test_expect_success "'ipfs object get --encoding=text' returns the correct content type" ' + curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=text" | grep -q "^Content-Type:\s*text/plain" + ' + + test_expect_success "'ipfs object get --encoding=xml' returns the correct content type" ' + curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=xml" | grep -q "^Content-Type:\s*application/xml" + ' + test_expect_success "'ipfs object get' output looks good" ' test_cmp ../t0051-object-data/expected_getOut actual_getOut '