Skip to content

Commit

Permalink
Merge pull request #139 from projectdiscovery/issue-138-empty-http-re…
Browse files Browse the repository at this point in the history
…sp-read-with-proxy

fix empty http resp with proxy
  • Loading branch information
Mzack9999 authored Apr 20, 2023
2 parents dfba03c + 8726dcf commit 9261ad8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion http/httputil.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package httputil

import (
"bytes"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -43,7 +44,21 @@ func DumpResponseHeadersAndRaw(resp *http.Response) (headers, fullresp []byte, e
if err != nil {
return
}
fullresp, err = httputil.DumpResponse(resp, true)
// logic same as httputil.DumpResponse(resp, true) but handles
// the edge case when we get both error and data on reading resp.Body
var buf1, buf2 bytes.Buffer
b := resp.Body
if _, err = buf1.ReadFrom(b); err != nil {
if buf1.Len() <= 0 {
return
}
}
if err == nil {
_ = b.Close()
}
resp.Body = io.NopCloser(bytes.NewReader(buf1.Bytes()))
err = resp.Write(&buf2)
fullresp = buf2.Bytes()
return
}

Expand Down

0 comments on commit 9261ad8

Please sign in to comment.