mirror of https://github.com/gin-gonic/gin.git
Only accepting 3xx status codes when redirecting. Swapped location and code arguments for Redirect signature
This commit is contained in:
parent
e350ae7c7e
commit
64fb835e6f
|
@ -302,7 +302,7 @@ func main() {
|
||||||
Issuing a HTTP redirect is easy:
|
Issuing a HTTP redirect is easy:
|
||||||
|
|
||||||
```r.GET("/test", func(c *gin.Context) {
|
```r.GET("/test", func(c *gin.Context) {
|
||||||
c.Redirect("http://www.google.com/", 302)
|
c.Redirect(301, "http://www.google.com/")
|
||||||
})
|
})
|
||||||
|
|
||||||
Both internal and external locations are supported.
|
Both internal and external locations are supported.
|
||||||
|
|
|
@ -248,8 +248,12 @@ func (c *Context) String(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(location string, code int) {
|
func (c *Context) Redirect(code int, location string) {
|
||||||
|
if code >= 300 && code <= 308 {
|
||||||
c.Render(code, render.Redirect, location)
|
c.Render(code, render.Redirect, location)
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("Cannot send a redirect with status code %d", code))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes some data into the body stream and updates the HTTP code.
|
// Writes some data into the body stream and updates the HTTP code.
|
||||||
|
|
Loading…
Reference in New Issue