Enhance API path normalization and configuration validation
- Introduced a new function to normalize request URL paths, collapsing duplicate slashes and clearing raw paths to ensure correct routing in the reverse proxy. - Updated the gateway to utilize the normalization function for API requests, improving routing consistency. - Trimmed whitespace from server configuration fields in the validation process to prevent potential issues with malformed URLs. - Enhanced documentation in GATEWAY_RUN.md to clarify the importance of proper URL formatting and configuration.
This commit is contained in:
@@ -228,6 +228,10 @@ func (g *Gateway) serve(w http.ResponseWriter, r *http.Request) {
|
||||
g.promHandler.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
// So /api//mtg/health and /api/../api/agg/... route like /api/mtg/health and /api/agg/...
|
||||
if strings.HasPrefix(r.URL.Path, "/api") {
|
||||
proxy.NormalizeRequestURLPath(r)
|
||||
}
|
||||
const prefix = "/api/"
|
||||
if r.URL.Path == "/api/agg" || strings.HasPrefix(r.URL.Path, "/api/agg/") {
|
||||
g.agg.ServeHTTP(w, r)
|
||||
|
||||
Reference in New Issue
Block a user