diff --git a/middleware.go b/middleware.go index 1e1ef7a..3f30063 100644 --- a/middleware.go +++ b/middleware.go @@ -92,7 +92,13 @@ func proxyToBackend(w http.ResponseWriter, r *http.Request) { 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 { http.Error(w, "proxy error", http.StatusInternalServerError) return diff --git a/proxy.go b/proxy.go index e95f3a5..5079b14 100644 --- a/proxy.go +++ b/proxy.go @@ -27,10 +27,14 @@ func inspect(r *http.Request) (int, error) { 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{}{ "method": r.Method, - "url": r.URL.String(), + "url": originalPath, "host": r.Host, "remote_addr": r.RemoteAddr, "content_type": r.Header.Get("Content-Type"),