mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-20 00:02:16 +08:00
Refactor redirect request in gin.go
This commit is contained in:
parent
6f7276fdc1
commit
7cde24a8e3
@ -8,7 +8,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const defaultMemory = 32 * 1024 * 1024
|
||||
const defaultMemory = 32 << 20
|
||||
|
||||
type formBinding struct{}
|
||||
type formPostBinding struct{}
|
||||
|
16
gin.go
16
gin.go
@ -455,9 +455,7 @@ func redirectTrailingSlash(c *Context) {
|
||||
if length := len(p); length > 1 && p[length-1] == '/' {
|
||||
req.URL.Path = p[:length-1]
|
||||
}
|
||||
debugPrint("redirecting request %d: %s --> %s", code, p, req.URL.String())
|
||||
http.Redirect(c.Writer, req, req.URL.String(), code)
|
||||
c.writermem.WriteHeaderNow()
|
||||
redirectRequest(c, code)
|
||||
}
|
||||
|
||||
func redirectFixedPath(c *Context, root *node, trailingSlash bool) bool {
|
||||
@ -470,10 +468,16 @@ func redirectFixedPath(c *Context, root *node, trailingSlash bool) bool {
|
||||
code = http.StatusTemporaryRedirect
|
||||
}
|
||||
req.URL.Path = string(fixedPath)
|
||||
debugPrint("redirecting request %d: %s --> %s", code, rPath, req.URL.String())
|
||||
http.Redirect(c.Writer, req, req.URL.String(), code)
|
||||
c.writermem.WriteHeaderNow()
|
||||
redirectRequest(c, code)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func redirectRequest(c *Context, code int) {
|
||||
rPath := c.Request.URL.Path
|
||||
rURL := c.Request.URL.String()
|
||||
debugPrint("redirecting request %d: %s --> %s", code, rPath, rURL)
|
||||
http.Redirect(c.Writer, c.Request, rURL, code)
|
||||
c.writermem.WriteHeaderNow()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user