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 · 2 comments · May be fixed by #306
Open

Use optional headers in DownloadableFile messages when fetching files #299

tpaschalis opened this issue Sep 18, 2024 · 2 comments · May be fixed by #306

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
}

@RichardChukwu
Copy link

RichardChukwu commented Oct 22, 2024

Is this still valid? I'd like to take it up if you're not working on it @tpaschalis

@tpaschalis
Copy link
Member Author

Yes it is still valid! I'm not sure I'll have the time to review the PR right away, but I'll make an effort.

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

Successfully merging a pull request may close this issue.

2 participants