High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(proxy): forward the inbound length only when the rewrite hook kept the body (PIN-367)
Luigi Agosti7e601d85a3a2
diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.goindex 2cc0a593..b13705ce 100644--- a/internal/proxy/proxy.go+++ b/internal/proxy/proxy.go@@ -74,6 +74,10 @@ func Forward(w http.ResponseWriter, r *http.Request, targetURL *url.URL, opts OpproxyReq.Header = r.Header.Clone()activity.PropagateHeaders(r.Context(), proxyReq)hostBeforeRewrite := proxyReq.Host+ inboundBody := &inboundRequestBody{ReadCloser: proxyReq.Body}+ if proxyReq.Body != nil {+ proxyReq.Body = inboundBody+ }if opts.RewriteRequest != nil {opts.RewriteRequest(proxyReq)}@@ -114,9 +118,11 @@ func Forward(w http.ResponseWriter, r *http.Request, targetURL *url.URL, opts Op// Only a rewrite propagates a Host. Left alone, the transport derives the// Host header from the URL as before, which spells a default port the way// the wire expects rather than the way targetURL.Host holds it.- outReq.ContentLength = proxyReq.ContentLength- if proxyReq.ContentLength == 0 {- outReq.Body = http.NoBody+ if body, unchanged := proxyReq.Body.(*inboundRequestBody); unchanged && body == inboundBody {+ outReq.ContentLength = proxyReq.ContentLength+ if proxyReq.ContentLength == 0 {+ outReq.Body = http.NoBody+ }}if proxyReq.Host != hostBeforeRewrite {outReq.Host = proxyReq.Host@@ -241,3 +247,7 @@ func copyRequestHeaders(dst, src http.Header) {}}}++type inboundRequestBody struct {+ io.ReadCloser+}