fix: restore original request path from X-Zoraxy-Uri header when proxying to backend

This commit is contained in:
Claus Lohmar 2026-08-07 13:14:35 +00:00
parent 3b7af072a0
commit d0b85fb635
2 changed files with 13 additions and 3 deletions

View file

@ -92,7 +92,13 @@ func proxyToBackend(w http.ResponseWriter, r *http.Request) {
return return
} }
proxyReq, err := http.NewRequestWithContext(r.Context(), r.Method, target.String()+r.URL.Path, r.Body) // Restore the original URI that Zoraxy captured (stripped of /inspect prefix).
originalPath := r.Header.Get("X-Zoraxy-Uri")
if originalPath == "" {
originalPath = r.URL.Path
}
proxyReq, err := http.NewRequestWithContext(r.Context(), r.Method, target.String()+originalPath, r.Body)
if err != nil { if err != nil {
http.Error(w, "proxy error", http.StatusInternalServerError) http.Error(w, "proxy error", http.StatusInternalServerError)
return return

View file

@ -27,10 +27,14 @@ func inspect(r *http.Request) (int, error) {
r.Body = io.NopCloser(io.MultiReader(bytes.NewReader(bodySample), r.Body)) r.Body = io.NopCloser(io.MultiReader(bytes.NewReader(bodySample), r.Body))
} }
// Build inspection payload. // Build inspection payload with the original URI.
originalPath := r.Header.Get("X-Zoraxy-Uri")
if originalPath == "" {
originalPath = r.URL.String()
}
payload, err := json.Marshal(map[string]interface{}{ payload, err := json.Marshal(map[string]interface{}{
"method": r.Method, "method": r.Method,
"url": r.URL.String(), "url": originalPath,
"host": r.Host, "host": r.Host,
"remote_addr": r.RemoteAddr, "remote_addr": r.RemoteAddr,
"content_type": r.Header.Get("Content-Type"), "content_type": r.Header.Get("Content-Type"),