Skip to content

Commit 351aea3

Browse files
committed
Fix __kitspace not returning redirect status codes
It was following redirects instead of passing the status code onto the browser.
1 parent d1342b3 commit 351aea3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

routers/web/kitspace.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,27 @@ func Kitspace(ctx *context.Context) {
4747
req, _ := http.NewRequest("GET", url.String(), bytes.NewBuffer(b))
4848
req.Header.Add("Content-Type", "application/json")
4949

50-
resp, err := http.DefaultClient.Do(req)
50+
// a http client that doesn't follow redirects, since we want the user's
51+
// browser to get the redirect status codes instead
52+
client := &http.Client{
53+
CheckRedirect: func(req *http.Request, via []*http.Request) error {
54+
return http.ErrUseLastResponse
55+
},
56+
}
57+
58+
resp, err := client.Do(req)
59+
5160
if err != nil {
5261
panic(err)
5362
}
5463

5564
ctx.Resp.Header().Set("Content-Type", resp.Header.Get("Content-Type"))
5665

66+
location := resp.Header.Get("Location")
67+
if location != "" {
68+
ctx.Resp.Header().Set("Location", location)
69+
}
70+
5771
defer resp.Body.Close()
5872
body, err := ioutil.ReadAll(resp.Body)
5973
if err != nil {

0 commit comments

Comments
 (0)