@cryptotaxi247 / kubo / commits / a72d26b87

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>

Steven Allen committed Mar 30, 2016 at 11:32 UTC a72d26b875ec5cd610a256446ed3c9358b177c98
4 files changed +29 -7
commands/http/handler.go
+4 -3
@@ -65,9 +65,10 @@ const (
65 )
66
67 var mimeTypes = map[string]string{
68 - cmds.JSON: "application/json",
69 - cmds.XML: "application/xml",
70 - cmds.Text: "text/plain",
68 + cmds.Protobuf: "application/protobuf",
69 + cmds.JSON: "application/json",
70 + cmds.XML: "application/xml",
71 + cmds.Text: "text/plain",
72 }
73
74 type ServerConfig struct {
commands/response.go
+4 -3
@@ -36,9 +36,10 @@ type EncodingType string
36
37 // Supported EncodingType constants.
38 const (
39 - JSON = "json"
40 - XML = "xml"
41 - Text = "text"
39 + JSON = "json"
40 + XML = "xml"
41 + Protobuf = "protobuf"
42 + Text = "text"
43 // TODO: support more encoding types
44 )
45
core/commands/object/object.go
+1 -1
@@ -222,7 +222,7 @@ This command outputs data in the following encodings:
222 },
223 Type: Node{},
224 Marshalers: cmds.MarshalerMap{
225 - cmds.EncodingType("protobuf"): func(res cmds.Response) (io.Reader, error) {
225 + cmds.Protobuf: func(res cmds.Response) (io.Reader, error) {
226 node := res.Output().(*Node)
227 object, err := deserializeNode(node)
228 if err != nil {
test/sharness/t0051-object.sh
+20
@@ -266,12 +266,32 @@ test_object_cmd() {
266 '
267 }
268
269 +test_object_content_type() {
270 +
271 + test_expect_success "'ipfs object get --encoding=protobuf' returns the correct content type" '
272 + curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=protobuf" | grep -q "^Content-Type: application/protobuf"
273 + '
274 +
275 + test_expect_success "'ipfs object get --encoding=json' returns the correct content type" '
276 + curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=json" | grep -q "^Content-Type: application/json"
277 + '
278 +
279 + test_expect_success "'ipfs object get --encoding=text' returns the correct content type" '
280 + curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=text" | grep -q "^Content-Type: text/plain"
281 + '
282 +
283 + test_expect_success "'ipfs object get --encoding=xml' returns the correct content type" '
284 + curl -sI "http://$API_ADDR/api/v0/object/get?arg=$HASH&encoding=xml" | grep -q "^Content-Type: application/xml"
285 + '
286 +}
287 +
288 # should work offline
289 test_object_cmd
290
291 # should work online
292 test_launch_ipfs_daemon
293 test_object_cmd
294 +test_object_content_type
295 test_kill_ipfs_daemon
296
297 test_done