From 351aea301fad4e9084962870764d5a407e008a8c Mon Sep 17 00:00:00 2001 From: Kaspar Emanuel Date: Wed, 2 Feb 2022 22:32:19 +0000 Subject: [PATCH] Fix __kitspace not returning redirect status codes It was following redirects instead of passing the status code onto the browser. --- routers/web/kitspace.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/routers/web/kitspace.go b/routers/web/kitspace.go index 7688f9335365..8e67f31125d9 100644 --- a/routers/web/kitspace.go +++ b/routers/web/kitspace.go @@ -47,13 +47,27 @@ func Kitspace(ctx *context.Context) { req, _ := http.NewRequest("GET", url.String(), bytes.NewBuffer(b)) req.Header.Add("Content-Type", "application/json") - resp, err := http.DefaultClient.Do(req) + // a http client that doesn't follow redirects, since we want the user's + // browser to get the redirect status codes instead + client := &http.Client{ + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, + } + + resp, err := client.Do(req) + if err != nil { panic(err) } ctx.Resp.Header().Set("Content-Type", resp.Header.Get("Content-Type")) + location := resp.Header.Get("Location") + if location != "" { + ctx.Resp.Header().Set("Location", location) + } + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil {