summaryrefslogtreecommitdiff
path: root/pkg/bindings/connection.go
diff options
context:
space:
mode:
authorMoritz "WanzenBug" Wanzenböck <moritz@wanzenbug.xyz>2021-11-15 15:42:39 +0100
committerMoritz "WanzenBug" Wanzenböck <moritz@wanzenbug.xyz>2021-11-15 15:42:39 +0100
commit5df883e87d7d4faec24c53c89bab3255057de0bc (patch)
tree933a4e9cb734652ac7523f86ba3df3c84b84fe12 /pkg/bindings/connection.go
parentcca6df428cb9ce187ae1341740ac1137c7a67a75 (diff)
downloadpodman-5df883e87d7d4faec24c53c89bab3255057de0bc.tar.gz
podman-5df883e87d7d4faec24c53c89bab3255057de0bc.tar.bz2
podman-5df883e87d7d4faec24c53c89bab3255057de0bc.zip
bindings: reuse context for API requests
One of the main uses of context.Context is to provide cancellation for go-routines, including API requests. While all user-facing bindings already used a context parameter, it was only used to pass the client information around. This commit changes the internal DoRequest wrapper to take an additional context argument, and pass that to the http request. Previously, the context was derived from context.Background(), which made it impossible to cancel once started. All the convenience wrappers already supported the context parameter, so the only user facing change is that cancelling those context now works as one would expect. Signed-off-by: Moritz "WanzenBug" Wanzenböck <moritz@wanzenbug.xyz>
Diffstat (limited to 'pkg/bindings/connection.go')
-rw-r--r--pkg/bindings/connection.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go
index a2be44ab4..b2e949f67 100644
--- a/pkg/bindings/connection.go
+++ b/pkg/bindings/connection.go
@@ -145,7 +145,7 @@ func pingNewConnection(ctx context.Context) error {
return err
}
// the ping endpoint sits at / in this case
- response, err := client.DoRequest(nil, http.MethodGet, "/_ping", nil, nil)
+ response, err := client.DoRequest(ctx, nil, http.MethodGet, "/_ping", nil, nil)
if err != nil {
return err
}
@@ -306,7 +306,7 @@ func unixClient(_url *url.URL) Connection {
}
// DoRequest assembles the http request and returns the response
-func (c *Connection) DoRequest(httpBody io.Reader, httpMethod, endpoint string, queryParams url.Values, header map[string]string, pathValues ...string) (*APIResponse, error) {
+func (c *Connection) DoRequest(ctx context.Context, httpBody io.Reader, httpMethod, endpoint string, queryParams url.Values, header map[string]string, pathValues ...string) (*APIResponse, error) {
var (
err error
response *http.Response
@@ -328,7 +328,7 @@ func (c *Connection) DoRequest(httpBody io.Reader, httpMethod, endpoint string,
uri := fmt.Sprintf("http://d/v%d.%d.%d/libpod"+endpoint, params...)
logrus.Debugf("DoRequest Method: %s URI: %v", httpMethod, uri)
- req, err := http.NewRequestWithContext(context.WithValue(context.Background(), clientKey, c), httpMethod, uri, httpBody)
+ req, err := http.NewRequestWithContext(ctx, httpMethod, uri, httpBody)
if err != nil {
return nil, err
}