add prefix from X-Forwarded-Prefix in redirectTrailingSlash

This commit is contained in:
Tudor Roman 2018-01-28 15:10:03 +02:00
parent 783c7ee9c1
commit 0906ea946d
No known key found for this signature in database
GPG Key ID: 5AFEDD03CA5A1EA4

9
gin.go
View File

@ -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