@cryptotaxi247 / kubo / commits / 7c7888c4d

fix(gateway): fix status code for HEAD on redirects

Report a consistent status code for HEAD requests that end up in a redirect.

Peter Wu committed May 20, 2020 at 13:21 UTC 7c7888c4db5a0d552ec174687275549fdd0908fd
1 file changed +9 -9
core/corehttp/gateway_handler.go
+9 -9
@@ -291,6 +291,15 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
291 return
292 }
293
294 + // See statusResponseWriter.WriteHeader
295 + // and https://github.com/ipfs/go-ipfs/issues/7164
296 + // Note: this needs to occur before listingTemplate.Execute otherwise we get
297 + // superfluous response.WriteHeader call from prometheus/client_golang
298 + if w.Header().Get("Location") != "" {
299 + w.WriteHeader(http.StatusMovedPermanently)
300 + return
301 + }
302 +
303 if r.Method == http.MethodHead {
304 return
305 }
@@ -350,15 +359,6 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
359 Hash: hash,
360 }
361
353 - // See statusResponseWriter.WriteHeader
354 - // and https://github.com/ipfs/go-ipfs/issues/7164
355 - // Note: this needs to occur before listingTemplate.Execute otherwise we get
356 - // superfluous response.WriteHeader call from prometheus/client_golang
357 - if w.Header().Get("Location") != "" {
358 - w.WriteHeader(http.StatusMovedPermanently)
359 - return
360 - }
361 -
362 err = listingTemplate.Execute(w, tplData)
363 if err != nil {
364 internalWebError(w, err)