From 66a9f516e200eb14960a3897f20d03d9a9c095d7 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 11 Oct 2022 11:46:57 +0200 Subject: [PATCH] feat: allow json and cbor data types too --- core/corehttp/gateway_handler.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index 445238694a6..d993a5f662f 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -431,11 +431,25 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request carVersion := formatParams["version"] i.serveCAR(r.Context(), w, r, resolvedPath, contentPath, carVersion, begin) return - case "application/vnd.ipld.dag-json", "application/json": + case "application/json": + if resolvedPath.Cid().Prefix().Codec == uint64(mc.Json) { + logger.Debugw("serving json", "path", contentPath) + i.serveCodec(r.Context(), w, r, resolvedPath, contentPath, begin, responseFormat, uint64(mc.Json)) + return + } + fallthrough + case "application/vnd.ipld.dag-json": logger.Debugw("serving dag-json", "path", contentPath) i.serveCodec(r.Context(), w, r, resolvedPath, contentPath, begin, responseFormat, uint64(mc.DagJson)) return - case "application/vnd.ipld.dag-cbor", "application/cbor": + case "application/cbor": + if resolvedPath.Cid().Prefix().Codec == uint64(mc.Cbor) { + logger.Debugw("serving cbor", "path", contentPath) + i.serveCodec(r.Context(), w, r, resolvedPath, contentPath, begin, responseFormat, uint64(mc.Cbor)) + return + } + fallthrough + case "application/vnd.ipld.dag-cbor": logger.Debugw("serving dag-cbor", "path", contentPath) i.serveCodec(r.Context(), w, r, resolvedPath, contentPath, begin, responseFormat, uint64(mc.DagCbor)) return