fix: log the original path being redirected

This commit is contained in:
wgdzlh 2022-07-21 11:37:52 +08:00
parent b57163a0e4
commit 4abcec5fbc

7
gin.go
View File

@ -674,7 +674,7 @@ func redirectTrailingSlash(c *Context) {
if length := len(p); length > 1 && p[length-1] == '/' { if length := len(p); length > 1 && p[length-1] == '/' {
req.URL.Path = p[:length-1] req.URL.Path = p[:length-1]
} }
redirectRequest(c) redirectRequest(c, p)
} }
func redirectFixedPath(c *Context, root *node, trailingSlash bool) bool { func redirectFixedPath(c *Context, root *node, trailingSlash bool) bool {
@ -683,15 +683,14 @@ func redirectFixedPath(c *Context, root *node, trailingSlash bool) bool {
if fixedPath, ok := root.findCaseInsensitivePath(cleanPath(rPath), trailingSlash); ok { if fixedPath, ok := root.findCaseInsensitivePath(cleanPath(rPath), trailingSlash); ok {
req.URL.Path = bytesconv.BytesToString(fixedPath) req.URL.Path = bytesconv.BytesToString(fixedPath)
redirectRequest(c) redirectRequest(c, rPath)
return true return true
} }
return false return false
} }
func redirectRequest(c *Context) { func redirectRequest(c *Context, rPath string) {
req := c.Request req := c.Request
rPath := req.URL.Path
rURL := req.URL.String() rURL := req.URL.String()
code := http.StatusMovedPermanently // Permanent redirect, request with GET method code := http.StatusMovedPermanently // Permanent redirect, request with GET method