mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
26236f491e
This unifies the methods to obtain the X-Forwarded-* header values and provides logical fallbacks. In addition, so we can ensure this functionality extends to the templated files we've converted the ServeTemplatedFile method into a function that operates as a middlewares.RequestHandler. Fixes #2765
24 lines
502 B
Go
24 lines
502 B
Go
package middlewares
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
// StripPathMiddleware strips the first level of a path.
|
|
func StripPathMiddleware(path string, next fasthttp.RequestHandler) fasthttp.RequestHandler {
|
|
return func(ctx *fasthttp.RequestCtx) {
|
|
uri := ctx.RequestURI()
|
|
|
|
if strings.HasPrefix(string(uri), path) {
|
|
ctx.SetUserValueBytes(UserValueKeyBaseURL, path)
|
|
|
|
newURI := strings.TrimPrefix(string(uri), path)
|
|
ctx.Request.SetRequestURI(newURI)
|
|
}
|
|
|
|
next(ctx)
|
|
}
|
|
}
|