- Replaced the existing reverse proxy implementation with a new alias forwarding mechanism, improving path handling and request normalization. - Updated the gateway to utilize the new forwarding approach, ensuring consistent handling of API requests and proper error management. - Enhanced tests to validate the new routing behavior, including handling of double slashes and user endpoint requests. - Improved documentation in GATEWAY_RUN.md to clarify the updated API routing and configuration requirements.
30 lines
656 B
Go
30 lines
656 B
Go
package proxy
|
|
|
|
import (
|
|
"net/http"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
// NormalizeRequestURLPath collapses duplicate slashes and dot-segments in req.URL.Path
|
|
// (path.Clean) and clears RawPath so strip-prefix routing matches the client path even
|
|
// when the request line contained "//" (e.g. /api//mtg/health). Without this, the path
|
|
// may not match /api/{alias} and alias routing fails.
|
|
func NormalizeRequestURLPath(req *http.Request) {
|
|
if req == nil || req.URL == nil {
|
|
return
|
|
}
|
|
u := req.URL
|
|
if u.Path == "" {
|
|
u.Path = "/"
|
|
u.RawPath = ""
|
|
return
|
|
}
|
|
c := path.Clean(u.Path)
|
|
if !strings.HasPrefix(c, "/") {
|
|
c = "/" + c
|
|
}
|
|
u.Path = c
|
|
u.RawPath = ""
|
|
}
|