1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-08-10 22:51:31 +02:00

Merge commit from fork

Signed-off-by: Jan Larwig <jan@larwig.com>
This commit is contained in:
Jan Larwig
2025-07-30 19:46:58 +02:00
committed by GitHub
parent f4b33b64bd
commit 9ffafad4b2
4 changed files with 85 additions and 14 deletions

View File

@@ -2,6 +2,8 @@ package util
import (
"net/http"
"net/url"
"strings"
middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
)
@@ -43,6 +45,25 @@ func GetRequestURI(req *http.Request) string {
return uri
}
// GetRequestPath returns the request URI or X-Forwarded-Uri if present and the
// request is proxied but always strips the query parameters and only returns
// the pure path
func GetRequestPath(req *http.Request) string {
uri := GetRequestURI(req)
// Parse URI and return only the path component
if parsedURL, err := url.Parse(uri); err == nil {
return parsedURL.Path
}
// Fallback: strip query parameters manually
if idx := strings.Index(uri, "?"); idx != -1 {
return uri[:idx]
}
return uri
}
// IsProxied determines if a request was from a proxy based on the RequestScope
// ReverseProxy tracker.
func IsProxied(req *http.Request) bool {