mirror of
https://github.com/mailgun/groupcache.git
synced 2024-10-02 21:02:08 +00:00
http requests now respect context.Context done
This commit is contained in:
parent
9dade9087a
commit
a5eee224aa
11
http.go
11
http.go
@ -18,6 +18,7 @@ package groupcache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -223,7 +224,7 @@ var bufferPool = sync.Pool{
|
|||||||
New: func() interface{} { return new(bytes.Buffer) },
|
New: func() interface{} { return new(bytes.Buffer) },
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpGetter) makeRequest(context Context, method string, in *pb.GetRequest, out *http.Response) error {
|
func (h *httpGetter) makeRequest(ctx Context, method string, in *pb.GetRequest, out *http.Response) error {
|
||||||
u := fmt.Sprintf(
|
u := fmt.Sprintf(
|
||||||
"%v%v/%v",
|
"%v%v/%v",
|
||||||
h.baseURL,
|
h.baseURL,
|
||||||
@ -234,9 +235,15 @@ func (h *httpGetter) makeRequest(context Context, method string, in *pb.GetReque
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If user passed a standard context object, use it in the request.
|
||||||
|
if stdCtx, ok := ctx.(context.Context); ok {
|
||||||
|
req = req.WithContext(stdCtx)
|
||||||
|
}
|
||||||
|
|
||||||
tr := http.DefaultTransport
|
tr := http.DefaultTransport
|
||||||
if h.transport != nil {
|
if h.transport != nil {
|
||||||
tr = h.transport(context)
|
tr = h.transport(ctx)
|
||||||
}
|
}
|
||||||
res, err := tr.RoundTrip(req)
|
res, err := tr.RoundTrip(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user