9da8d5b4
fix: correct log ordering and body read error handling in proxy
a73x 2026-03-29 16:29
diff --git a/proxy/proxy.go b/proxy/proxy.go index f3fc126..616636e 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -53,9 +53,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } log.Printf("ALLOWED %s %s", r.Method, r.Host) if r.Method == http.MethodConnect { log.Printf("ALLOWED %s %s", r.Method, r.Host) p.handleConnect(w, r) return } @@ -125,11 +124,12 @@ func (p *Proxy) scanRequest(r *http.Request) []scanner.Finding { // Read body if present if r.Body != nil { body, err := io.ReadAll(r.Body) if err == nil { buf.Write(body) // Restore the body so it can be forwarded r.Body = io.NopCloser(bytes.NewReader(body)) if err != nil { log.Printf("WARNING: failed to read request body: %v", err) return nil } buf.Write(body) r.Body = io.NopCloser(bytes.NewReader(body)) } return p.scanner.Scan(buf.Bytes()) @@ -147,6 +147,7 @@ func (p *Proxy) handleHTTP(w http.ResponseWriter, r *http.Request) { return } log.Printf("ALLOWED %s %s", r.Method, r.Host) r.RequestURI = "" resp, err := http.DefaultTransport.RoundTrip(r) if err != nil {