From 8b5f5e0881e92d0ec728cf845f3f04d8d2f941e5 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 20 Oct 2022 13:47:46 +0200 Subject: [PATCH] fix: add missing traversal --- core/corehttp/gateway_handler_codec.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/corehttp/gateway_handler_codec.go b/core/corehttp/gateway_handler_codec.go index 95defa956dd..42d5b56db14 100644 --- a/core/corehttp/gateway_handler_codec.go +++ b/core/corehttp/gateway_handler_codec.go @@ -14,6 +14,7 @@ import ( "github.com/ipfs/kubo/tracing" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/multicodec" + "github.com/ipld/go-ipld-prime/traversal" mc "github.com/multiformats/go-multicodec" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -95,6 +96,16 @@ func (i *gatewayHandler) serveCodec(ctx context.Context, w http.ResponseWriter, } finalNode := universal.(ipld.Node) + if len(resolvedPath.Remainder()) > 0 { + remainderPath := ipld.ParsePath(resolvedPath.Remainder()) + + finalNode, err = traversal.Get(finalNode, remainderPath) + if err != nil { + webError(w, err.Error(), err, http.StatusInternalServerError) + return + } + } + // Otherwise convert it using the last codec of the list. encoder, err := multicodec.LookupEncoder(codecs[len(codecs)-1]) if err != nil {