Skip to content

Commit

Permalink
Fix __kitspace not returning redirect status codes
Browse files Browse the repository at this point in the history
It was following redirects instead of passing the status code onto the
browser.
  • Loading branch information
kasbah committed Feb 2, 2022
1 parent d1342b3 commit 351aea3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion routers/web/kitspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 351aea3

Please sign in to comment.