In the core's response.go, add an optional RedirectCodeSetter field or variadic use303 ...bool parameter to Redirect() and use the stored code + http.StatusSeeOther in core.go instead of the hardcoded http.StatusTemporaryRedirect, so that a POST handler can redirect to a GET route by calling c.Response.Redirect("/url", true).
This commit is contained in:
parent
262c5befd9
commit
8446f6fb2a
2 changed files with 17 additions and 3 deletions
6
core.go
6
core.go
|
|
@ -308,7 +308,11 @@ func (app *App) makeHTTPRouterHandlerFunc(h Controller, ms []Hook) httprouter.Ha
|
|||
w.WriteHeader(ctx.Response.statusCode)
|
||||
}
|
||||
if ctx.Response.redirectTo != "" {
|
||||
http.Redirect(w, r, ctx.Response.redirectTo, http.StatusTemporaryRedirect)
|
||||
statusCode := ctx.Response.redirectStatusCode
|
||||
if statusCode == 0 {
|
||||
statusCode = http.StatusTemporaryRedirect // default to 307
|
||||
}
|
||||
http.Redirect(w, r, ctx.Response.redirectTo, statusCode)
|
||||
} else {
|
||||
w.Write(ctx.Response.body)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue