Skip to content

Commit 257cfd1

Browse files
authored
Merge pull request #5 from monasticacademy/fix-closed-body
Fix "invalid Read on closed Body" when using harlog
2 parents cb92ee3 + e66ae4f commit 257cfd1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/harlog/round_tripper.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ func (h *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
8989
// do the HTTP roundtrip
9090
resp, realErr := baseRoundTripper.RoundTrip(r)
9191

92-
err = h.postRoundTrip(resp, entry)
92+
err = nil
93+
if resp != nil {
94+
err = h.postRoundTrip(resp, entry)
95+
}
9396

9497
timings.endAt = time.Now()
9598
UpdateEntryWithTimings(entry, timings)
@@ -129,6 +132,8 @@ func (h *Transport) preRoundTrip(r *http.Request, entry *Entry) error {
129132
}
130133
}
131134

135+
r.Body = io.NopCloser(bytes.NewBuffer(body))
136+
132137
return UpdateEntryWithRequest(entry, r, body)
133138
}
134139

0 commit comments

Comments
 (0)