From e1dd5d93264450172cf44608c388416ff72cbb9f Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 15 Apr 2020 13:42:29 +0200 Subject: [PATCH] fix: subdomain redirect for dir CIDs Closes #7164 License: MIT Signed-off-by: Marcin Rataj This commit was moved from ipfs/kubo@8290ec11c376d8246a7e592eb4e6472479833077 --- gateway/core/corehttp/gateway_handler.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gateway/core/corehttp/gateway_handler.go b/gateway/core/corehttp/gateway_handler.go index d26f21d54..8c7cea134 100644 --- a/gateway/core/corehttp/gateway_handler.go +++ b/gateway/core/corehttp/gateway_handler.go @@ -342,6 +342,16 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request BackLink: backLink, Hash: hash, } + + // See statusResponseWriter.WriteHeader + // and https://github.com/ipfs/go-ipfs/issues/7164 + // Note: this needs to occur before listingTemplate.Execute otherwise we get + // superfluous response.WriteHeader call from prometheus/client_golang + if w.Header().Get("Location") != "" { + w.WriteHeader(http.StatusMovedPermanently) + return + } + err = listingTemplate.Execute(w, tplData) if err != nil { internalWebError(w, err)