|
|
@@ -30,8 +30,9 @@ func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Resp
|
|
|
client = http.DefaultClient
|
|
|
}
|
|
|
|
|
|
- // Request cancelation changed in Go 1.5, see cancelreq.go and cancelreq_go14.go.
|
|
|
- cancel := canceler(client, req)
|
|
|
+ // TODO(djd): Respect any existing value of req.Cancel.
|
|
|
+ cancel := make(chan struct{})
|
|
|
+ req.Cancel = cancel
|
|
|
|
|
|
type responseAndError struct {
|
|
|
resp *http.Response
|
|
|
@@ -55,7 +56,7 @@ func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Resp
|
|
|
select {
|
|
|
case <-ctx.Done():
|
|
|
testHookContextDoneBeforeHeaders()
|
|
|
- cancel()
|
|
|
+ close(cancel)
|
|
|
// Clean up after the goroutine calling client.Do:
|
|
|
go func() {
|
|
|
if r := <-result; r.resp != nil {
|
|
|
@@ -76,7 +77,7 @@ func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Resp
|
|
|
go func() {
|
|
|
select {
|
|
|
case <-ctx.Done():
|
|
|
- cancel()
|
|
|
+ close(cancel)
|
|
|
case <-c:
|
|
|
// The response's Body is closed.
|
|
|
}
|