diff options
Diffstat (limited to 'internal/pkg/net.go')
| -rw-r--r-- | internal/pkg/net.go | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/internal/pkg/net.go b/internal/pkg/net.go index 3415b6d1..737dfd85 100644 --- a/internal/pkg/net.go +++ b/internal/pkg/net.go @@ -12,8 +12,6 @@ import ( // hardcoded as [http.MethodGet]. Request body is not allowed because it cannot // be deterministically represented by Params. type httpArtifact struct { - // Caller-supplied context. - ctx context.Context // Caller-supplied url string. url string @@ -36,18 +34,14 @@ var _ KnownChecksum = new(httpArtifact) // NewHTTPGet returns a new [File] backed by the supplied client. A GET request // is set up for url. If c is nil, [http.DefaultClient] is used instead. func NewHTTPGet( - ctx context.Context, c *http.Client, url string, checksum Checksum, ) File { - if ctx == nil { - ctx = context.Background() - } if c == nil { c = http.DefaultClient } - return &httpArtifact{ctx: ctx, url: url, checksum: checksum, doFunc: c.Do} + return &httpArtifact{url: url, checksum: checksum, doFunc: c.Do} } // Kind returns the hardcoded [Kind] constant. @@ -73,9 +67,9 @@ func (e ResponseStatusError) Error() string { // do sends the caller-supplied request on the caller-supplied [http.Client] // and reads its response body to EOF and returns the resulting bytes. -func (a *httpArtifact) do() (data []byte, err error) { +func (a *httpArtifact) do(ctx context.Context) (data []byte, err error) { var req *http.Request - req, err = http.NewRequestWithContext(a.ctx, http.MethodGet, a.url, nil) + req, err = http.NewRequestWithContext(ctx, http.MethodGet, a.url, nil) if err != nil { return } @@ -101,7 +95,7 @@ func (a *httpArtifact) do() (data []byte, err error) { // Cure completes the http request and returns the resulting response body read // to EOF. Data does not interact with the filesystem. -func (a *httpArtifact) Cure() (data []byte, err error) { +func (a *httpArtifact) Cure(ctx context.Context) (data []byte, err error) { a.mu.Lock() defer a.mu.Unlock() @@ -110,7 +104,7 @@ func (a *httpArtifact) Cure() (data []byte, err error) { return a.data, nil } - if data, err = a.do(); err != nil { + if data, err = a.do(ctx); err != nil { return } |
