Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use optional headers in DownloadableFile messages when fetching files #299

Open
tpaschalis opened this issue Sep 18, 2024 · 0 comments
Open

Comments

@tpaschalis
Copy link
Member

A recent spec change enables the DownloadableFile message to set optional headers to use when downloading a file, for example to set up some authentication headers.

The change should be straightforward; the code path which downloads files ultimately ends up here:

// downloadFile downloads the file from the server.
func (s *packagesSyncer) downloadFile(ctx context.Context, pkgName string, file *protobufs.DownloadableFile) error {
s.logger.Debugf(ctx, "Downloading package %s file from %s", pkgName, file.DownloadUrl)
req, err := http.NewRequestWithContext(ctx, "GET", file.DownloadUrl, nil)
if err != nil {
return fmt.Errorf("cannot download file from %s: %v", file.DownloadUrl, err)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("cannot download file from %s: %v", file.DownloadUrl, err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("cannot download file from %s, HTTP response=%v", file.DownloadUrl, resp.StatusCode)
}
// TODO: either add a callback to verify file.Signature or pass the Signature
// as a parameter to UpdateContent.
err = s.localState.UpdateContent(ctx, pkgName, resp.Body, file.ContentHash)
if err != nil {
return fmt.Errorf("failed to install/update the package %s downloaded from %s: %v", pkgName, file.DownloadUrl, err)
}
return nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant