Skip to content

Commit

Permalink
fix empty http resp with proxy (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Apr 20, 2023
1 parent dfba03c commit 8726dcf
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 8726dcf

Please sign in to comment.