diff --git a/clientutil/json.go b/clientutil/json.go index 862d08630a3834b7c8b094c323138f4de16dd1a0..5fc1ab2e4ab75061c44e816c79a874c580c73a73 100644 --- a/clientutil/json.go +++ b/clientutil/json.go @@ -2,13 +2,17 @@ package clientutil import ( "bytes" + "context" "encoding/json" "errors" "fmt" "net/http" ) -func DoJSONHTTPRequest(client *http.Client, uri string, req, resp interface{}) error { +// DoJSONHTTPRequest makes an HTTP POST request to the specified uri, +// with a JSON-encoded request body. It will attempt to decode the +// response body as JSON. +func DoJSONHTTPRequest(ctx context.Context, client *http.Client, uri string, req, resp interface{}) error { data, err := json.Marshal(req) if err != nil { return err @@ -19,6 +23,7 @@ func DoJSONHTTPRequest(client *http.Client, uri string, req, resp interface{}) e return err } httpReq.Header.Set("Content-Type", "application/json") + httpReq = httpReq.WithContext(ctx) httpResp, err := RetryHTTPDo(client, httpReq, NewExponentialBackOff()) if err != nil {