mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 10:49:24 +08:00
Merge pull request #2516 from Stebalien/protobuf-content-type
Correctly set the content type for `object get --encoding=protobuf`
This commit is contained in:
@ -65,9 +65,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var mimeTypes = map[string]string{
|
var mimeTypes = map[string]string{
|
||||||
cmds.JSON: "application/json",
|
cmds.Protobuf: "application/protobuf",
|
||||||
cmds.XML: "application/xml",
|
cmds.JSON: "application/json",
|
||||||
cmds.Text: "text/plain",
|
cmds.XML: "application/xml",
|
||||||
|
cmds.Text: "text/plain",
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerConfig struct {
|
type ServerConfig struct {
|
||||||
|
@ -36,9 +36,10 @@ type EncodingType string
|
|||||||
|
|
||||||
// Supported EncodingType constants.
|
// Supported EncodingType constants.
|
||||||
const (
|
const (
|
||||||
JSON = "json"
|
JSON = "json"
|
||||||
XML = "xml"
|
XML = "xml"
|
||||||
Text = "text"
|
Protobuf = "protobuf"
|
||||||
|
Text = "text"
|
||||||
// TODO: support more encoding types
|
// TODO: support more encoding types
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ This command outputs data in the following encodings:
|
|||||||
},
|
},
|
||||||
Type: Node{},
|
Type: Node{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
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)
|
node := res.Output().(*Node)
|
||||||
// deserialize the Data field as text as this was the standard behaviour
|
// deserialize the Data field as text as this was the standard behaviour
|
||||||
object, err := deserializeNode(node, "text")
|
object, err := deserializeNode(node, "text")
|
||||||
|
@ -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
|
# should work offline
|
||||||
test_object_cmd
|
test_object_cmd
|
||||||
|
|
||||||
# should work online
|
# should work online
|
||||||
test_launch_ipfs_daemon
|
test_launch_ipfs_daemon
|
||||||
test_object_cmd
|
test_object_cmd
|
||||||
|
test_object_content_type
|
||||||
test_kill_ipfs_daemon
|
test_kill_ipfs_daemon
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Reference in New Issue
Block a user