From d2ee1d10d270c89d54eedaf0ed7dcfa6b05c90aa Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 10 Oct 2022 14:09:17 +0200 Subject: [PATCH] fix: return 400 if not unixfs --- core/corehttp/gateway_handler_tar.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/corehttp/gateway_handler_tar.go b/core/corehttp/gateway_handler_tar.go index 87936e8200db..7b7bb75f1ffa 100644 --- a/core/corehttp/gateway_handler_tar.go +++ b/core/corehttp/gateway_handler_tar.go @@ -23,6 +23,14 @@ func (i *gatewayHandler) serveTAR(ctx context.Context, w http.ResponseWriter, r ctx, cancel := context.WithCancel(ctx) defer cancel() + // Get Unixfs file + file, err := i.api.Unixfs().Get(ctx, resolvedPath) + if err != nil { + webError(w, "ipfs cat "+html.EscapeString(contentPath.String()), err, http.StatusBadRequest) + return + } + defer file.Close() + // Set Cache-Control and read optional Last-Modified time modtime := addCacheControlHeaders(w, r, contentPath, resolvedPath.Cid()) @@ -41,14 +49,6 @@ func (i *gatewayHandler) serveTAR(ctx context.Context, w http.ResponseWriter, r } setContentDispositionHeader(w, name, "attachment") - // Get Unixfs file - file, err := i.api.Unixfs().Get(ctx, resolvedPath) - if err != nil { - webError(w, "ipfs cat "+html.EscapeString(contentPath.String()), err, http.StatusNotFound) - return - } - defer file.Close() - // Construct the TAR writer tarw, err := files.NewTarWriter(w) if err != nil {