Skip to content

Commit

Permalink
http: make http client request with context (#132)
Browse files Browse the repository at this point in the history
* http: make request with context

- use ctx naming convention
- use context.TODO() instead of nil

Signed-off-by: Bobby DeSimone <[email protected]>
  • Loading branch information
desimone authored and bradfitz committed Jan 21, 2020
1 parent 215e871 commit 8c9f03a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ var bufferPool = sync.Pool{
New: func() interface{} { return new(bytes.Buffer) },
}

func (h *httpGetter) Get(context context.Context, in *pb.GetRequest, out *pb.GetResponse) error {
func (h *httpGetter) Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse) error {
u := fmt.Sprintf(
"%v%v/%v",
h.baseURL,
Expand All @@ -203,9 +203,10 @@ func (h *httpGetter) Get(context context.Context, in *pb.GetRequest, out *pb.Get
if err != nil {
return err
}
req = req.WithContext(ctx)
tr := http.DefaultTransport
if h.transport != nil {
tr = h.transport(context)
tr = h.transport(ctx)
}
res, err := tr.RoundTrip(req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestHTTPPool(t *testing.T) {

for _, key := range testKeys(nGets) {
var value string
if err := g.Get(nil, key, StringSink(&value)); err != nil {
if err := g.Get(context.TODO(), key, StringSink(&value)); err != nil {
t.Fatal(err)
}
if suffix := ":" + key; !strings.HasSuffix(value, suffix) {
Expand Down
2 changes: 1 addition & 1 deletion peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// ProtoGetter is the interface that must be implemented by a peer.
type ProtoGetter interface {
Get(context context.Context, in *pb.GetRequest, out *pb.GetResponse) error
Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResponse) error
}

// PeerPicker is the interface that must be implemented to locate
Expand Down

0 comments on commit 8c9f03a

Please sign in to comment.