Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Fix request-map not being cleared up after requests
Browse files Browse the repository at this point in the history
Fixes #62
  • Loading branch information
gregjones committed Feb 5, 2017
1 parent 4137817 commit 9c8ca9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions httpcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,22 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error
}
if req2 != nil {
// Associate original request with cloned request so we can refer to
// it in CancelRequest()
// it in CancelRequest(). Release the mapping when it's no longer needed.
t.setModReq(req, req2)
req = req2
defer func() {
defer func(originalReq *http.Request) {
// Release req/clone mapping on error
if err != nil {
t.setModReq(req, nil)
t.setModReq(originalReq, nil)
}
if resp != nil {
// Release req/clone mapping on body close/EOF
resp.Body = &onEOFReader{
rc: resp.Body,
fn: func() { t.setModReq(req, nil) },
fn: func() { t.setModReq(originalReq, nil) },
}
}
}()
}(req)
req = req2
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions httpcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ func TestGetWithLastModified(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer func() {
if len(s.transport.modReq) != 0 {
t.Errorf("Request-map is not empty")
}
}()
{
resp, err := s.client.Do(req)
if err != nil {
Expand Down

0 comments on commit 9c8ca9f

Please sign in to comment.