Skip to content

Commit

Permalink
Merge pull request #2516 from Stebalien/protobuf-content-type
Browse files Browse the repository at this point in the history
Correctly set the content type for `object get --encoding=protobuf`
  • Loading branch information
whyrusleeping committed May 29, 2016
2 parents eaaefd5 + a72d26b commit 6c33503
Show file tree
Hide file tree
Showing 4 changed files with 29 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 @@ -215,7 +215,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)
// deserialize the Data field as text as this was the standard behaviour
object, err := deserializeNode(node, "text")
Expand Down
20 changes: 20 additions & 0 deletions test/sharness/t0051-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,32 @@ test_object_cmd() {
'
}

test_object_content_type() {

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"
'
}

# should work offline
test_object_cmd

# should work online
test_launch_ipfs_daemon
test_object_cmd
test_object_content_type
test_kill_ipfs_daemon

test_done

0 comments on commit 6c33503

Please sign in to comment.