Skip to content

Commit

Permalink
api: correctly set the content type for object get --encoding=protobuf
Browse files Browse the repository at this point in the history
It used to default to `application/json` but is now correctly set to
`application/protobuf`.

fixes ipfs#2469

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
  • Loading branch information
Stebalien committed Mar 31, 2016
1 parent 87cf84e commit 8b2a8b4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
7 changes: 4 additions & 3 deletions commands/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions commands/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions test/sharness/t0051-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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: 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: 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: application/xml"
'

test_expect_success "'ipfs object get' output looks good" '
test_cmp ../t0051-object-data/expected_getOut actual_getOut
'
Expand Down

0 comments on commit 8b2a8b4

Please sign in to comment.