authelia/internal/middlewares/strip_path.go

24 lines
502 B
Go
Raw Normal View History

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)
}
}