Skip to content

Commit ce735f6

Browse files
committed
fix: empty location when status is 30x
1 parent 6be58b0 commit ce735f6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

server.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,14 @@ func (h *RegexpHandler) run(route *route, body []byte, w http.ResponseWriter, r
120120
for k, v := range fakeResp.HeaderMap() {
121121
w.Header().Set(k, v)
122122
}
123-
// todo: can this has a conflict?
123+
// todo: can this have a conflict?
124124
if len(fakeResp.status) != 0 {
125+
// fix go 302 error:
126+
// if the response is >300 and <400, the location must in response header
127+
status := fakeResp.status[0]
128+
if status > 300 && status < 400 && w.Header().Get("location") == "" {
129+
w.Header().Set("location", r.URL.Path)
130+
}
125131
w.WriteHeader(fakeResp.status[0])
126132
}
127133
_, _ = w.Write(fakeResp.body)

0 commit comments

Comments
 (0)