mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 17:42:14 +08:00
add prefix from X-Forwarded-Prefix in redirectTrailingSlash
This commit is contained in:
parent
783c7ee9c1
commit
0906ea946d
9
gin.go
9
gin.go
@ -9,6 +9,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
|
||||
"github.com/gin-gonic/gin/render"
|
||||
@ -405,7 +406,13 @@ func serveError(c *Context, code int, defaultMessage []byte) {
|
||||
|
||||
func redirectTrailingSlash(c *Context) {
|
||||
req := c.Request
|
||||
path := req.URL.Path
|
||||
prefix := path.Clean(c.Request.Header.Get("X-Forwarded-Prefix"))
|
||||
path := ""
|
||||
if prefix == "." {
|
||||
path = req.URL.Path
|
||||
} else {
|
||||
path = prefix + "/" + req.URL.Path
|
||||
}
|
||||
code := 301 // Permanent redirect, request with GET method
|
||||
if req.Method != "GET" {
|
||||
code = 307
|
||||
|
Loading…
x
Reference in New Issue
Block a user