Files
Denozordec 374b4e0d71
Publish telemt-api gateway Docker image / test (push) Failing after 26s
Publish telemt-api gateway Docker image / build-and-push (push) Has been skipped
Refactor reverse proxy and enhance API routing
- 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.
2026-03-30 11:47:50 +07:00

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 = ""
}