diff options
author | Agniva De Sarker <agnivade@yahoo.co.in> | 2018-12-13 14:14:49 +0530 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-12-21 16:45:03 +0000 |
commit | 7ed0a50146b4d79f8b1027b56aa37a966162f30e (patch) | |
tree | fb0c208a4e2acc0d5855ed71841fbe0012a575d0 | |
parent | 132b8627adca1170af1b36d3c471e99011ef6f8b (diff) |
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>
-rw-r--r-- | content/context/google/google.go | 6 |
1 files changed, 2 insertions, 4 deletions
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 @@ func Search(ctx context.Context, query string) (Results, error) { // 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: |