Context redirect uses the built-in redirect facility
This commit is contained in:
parent
c0e8cedc98
commit
3abeba82fc
@ -234,9 +234,9 @@ func (c *Context) HTMLString(code int, format string, values ...interface{}) {
|
|||||||
// Returns a HTTP redirect to the specific location.
|
// Returns a HTTP redirect to the specific location.
|
||||||
func (c *Context) Redirect(code int, location string) {
|
func (c *Context) Redirect(code int, location string) {
|
||||||
if code >= 300 && code <= 308 {
|
if code >= 300 && code <= 308 {
|
||||||
c.Render(code, render.Redirect, location)
|
c.Render(code, render.Redirect, c.Request, location)
|
||||||
} else {
|
} else {
|
||||||
log.Panicf("Cannot send a redirect with status code %d", code)
|
log.Panicf("Cannot redirect with status code %d", code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (_ redirectRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {
|
func (_ redirectRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {
|
||||||
w.Header().Set("Location", data[0].(string))
|
req := data[0].(*http.Request)
|
||||||
w.WriteHeader(code)
|
location := data[1].(string)
|
||||||
|
http.Redirect(w, req, location, code)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user