authelia/internal/middlewares/strip_path.go
James Elliott 0855ea2f71
fix(server): missing cache and xss headers (#3289)
Addresses documentation and a couple of headers which were missed.
2022-05-04 14:47:23 +10:00

26 lines
541 B
Go

package middlewares
import (
"strings"
"github.com/valyala/fasthttp"
)
// StripPath strips the first level of a path.
func StripPath(path string) (middleware StandardMiddleware) {
return func(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)
}
}
}