Skip to content

Commit

Permalink
Bugfix: Check cancel func prior to invoking it.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandotsmith committed Mar 5, 2015
1 parent 8e5d1e6 commit b3137ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions limit/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import (
"testing"
)

func TestCancel(t *testing.T) {
tr := &Transport{}
tr.CancelRequest(new(http.Request))
}

func TestSanity(t *testing.T) {
f := func(r *http.Request) interface{} { return 0 }
tr := &Transport{
Expand Down
4 changes: 3 additions & 1 deletion limit/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
// on the underlying RoundTripper.
func (t *Transport) CancelRequest(r *http.Request) {
cancel := t.setCanceler(r, nil)
cancel()
if cancel != nil {
cancel()
}
type canceler interface {
CancelRequest(*http.Request)
}
Expand Down

0 comments on commit b3137ac

Please sign in to comment.