content/context: use req.WithContext
(*Transport).CancelRequest is now deprecated. Use the new
(*Request).WithContext method which inherits the parent context.
Fixes golang/go#29075
Change-Id: I4a275a396c6ed64eef73b688a049e7bc372f07d4
Reviewed-on: https://go-review.googlesource.com/c/153957
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/content/context/google/google.go b/content/context/google/google.go
index 75442d0..e25cfc1 100644
--- a/content/context/google/google.go
+++ b/content/context/google/google.go
@@ -81,13 +81,11 @@
// for f to exit, and returns ctx.Err. Otherwise, httpDo returns f's error.
func httpDo(ctx context.Context, req *http.Request, f func(*http.Response, error) error) error {
// Run the HTTP request in a goroutine and pass the response to f.
- tr := &http.Transport{}
- client := &http.Client{Transport: tr}
c := make(chan error, 1)
- go func() { c <- f(client.Do(req)) }()
+ req = req.WithContext(ctx)
+ go func() { c <- f(http.DefaultClient.Do(req)) }()
select {
case <-ctx.Done():
- tr.CancelRequest(req)
<-c // Wait for f to return.
return ctx.Err()
case err := <-c: