9da8d5b4
fix: correct log ordering and body read error handling in proxy
a73x 2026-03-29 16:29
Commit message
proxy/proxy.go
| Old | New | ||
|---|---|---|---|
| @@ -53,9 +53,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
| 53 | return | 53 | return |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | log.Printf("ALLOWED %s %s", r.Method, r.Host) | ||
| 57 | |||
| 58 | if r.Method == http.MethodConnect { | 56 | if r.Method == http.MethodConnect { |
| 57 | log.Printf("ALLOWED %s %s", r.Method, r.Host) | ||
| 59 | p.handleConnect(w, r) | 58 | p.handleConnect(w, r) |
| 60 | return | 59 | return |
| 61 | } | 60 | } |
| @@ -125,11 +124,12 @@ func (p *Proxy) scanRequest(r *http.Request) []scanner.Finding { | |||
| 125 | // Read body if present | 124 | // Read body if present |
| 126 | if r.Body != nil { | 125 | if r.Body != nil { |
| 127 | body, err := io.ReadAll(r.Body) | 126 | body, err := io.ReadAll(r.Body) |
| 128 | if err == nil { | 127 | if err != nil { |
| 129 | buf.Write(body) | 128 | log.Printf("WARNING: failed to read request body: %v", err) |
| 130 | // Restore the body so it can be forwarded | 129 | return nil |
| 131 | r.Body = io.NopCloser(bytes.NewReader(body)) | ||
| 132 | } | 130 | } |
| 131 | buf.Write(body) | ||
| 132 | r.Body = io.NopCloser(bytes.NewReader(body)) | ||
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | return p.scanner.Scan(buf.Bytes()) | 135 | return p.scanner.Scan(buf.Bytes()) |
| @@ -147,6 +147,7 @@ func (p *Proxy) handleHTTP(w http.ResponseWriter, r *http.Request) { | |||
| 147 | return | 147 | return |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | log.Printf("ALLOWED %s %s", r.Method, r.Host) | ||
| 150 | r.RequestURI = "" | 151 | r.RequestURI = "" |
| 151 | resp, err := http.DefaultTransport.RoundTrip(r) | 152 | resp, err := http.DefaultTransport.RoundTrip(r) |
| 152 | if err != nil { | 153 | if err != nil { |