diff options
Diffstat (limited to 'internal/pkg/net.go')
| -rw-r--r-- | internal/pkg/net.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/internal/pkg/net.go b/internal/pkg/net.go index c481b52e..8726fcac 100644 --- a/internal/pkg/net.go +++ b/internal/pkg/net.go @@ -1,6 +1,7 @@ package pkg import ( + "bytes" "context" "crypto/sha512" "fmt" @@ -34,13 +35,13 @@ type httpArtifact struct { var _ KnownChecksum = new(httpArtifact) var _ fmt.Stringer = 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. +// NewHTTPGet returns a new [FileArtifact] backed by the supplied client. A GET +// request is set up for url. If c is nil, [http.DefaultClient] is used instead. func NewHTTPGet( c *http.Client, url string, checksum Checksum, -) File { +) FileArtifact { if c == nil { c = http.DefaultClient } @@ -103,15 +104,16 @@ func (a *httpArtifact) do(ctx context.Context) (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(ctx context.Context) (data []byte, err error) { +func (a *httpArtifact) Cure(ctx context.Context) (r io.ReadCloser, err error) { a.mu.Lock() defer a.mu.Unlock() if a.data != nil { - // validated by cache or a previous call to Data - return a.data, nil + // validated by cache or a previous call to Cure + return io.NopCloser(bytes.NewReader(a.data)), nil } + var data []byte if data, err = a.do(ctx); err != nil { return } @@ -122,5 +124,6 @@ func (a *httpArtifact) Cure(ctx context.Context) (data []byte, err error) { return nil, &ChecksumMismatchError{got, a.checksum} } a.data = data + r = io.NopCloser(bytes.NewReader(data)) return } |
