1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 02:30:39 +08:00

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 <steven@stebalien.com>
This commit is contained in:
Steven Allen
2016-03-30 11:32:23 -04:00
parent 8acd87d799
commit a72d26b875
4 changed files with 29 additions and 7 deletions

View File

@ -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 {

View File

@ -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
)

View File

@ -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 {

View File

@ -266,12 +266,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