-
Notifications
You must be signed in to change notification settings - Fork 4
fix: Allow asset download from private repos #24
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,11 +49,35 @@ impl Server { | |
| attempt.stop() | ||
| }); | ||
|
|
||
| let mut client_builder = Client::builder().redirect(policy); | ||
| if github.is_private() { | ||
| // Build client with GitHub authentication if token is available | ||
| if let Some(token) = github.token() { | ||
| let mut headers = reqwest::header::HeaderMap::new(); | ||
| let mut auth_value = format!("token {token}") | ||
| .parse::<reqwest::header::HeaderValue>() | ||
| .unwrap(); | ||
| auth_value.set_sensitive(true); | ||
| headers.insert(reqwest::header::AUTHORIZATION, auth_value); | ||
| headers.insert( | ||
| reqwest::header::USER_AGENT, | ||
| concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")) | ||
| .parse() | ||
| .unwrap(), | ||
| ); | ||
| headers.insert( | ||
| reqwest::header::ACCEPT, | ||
| "application/octet-stream".parse().unwrap(), | ||
| ); | ||
| client_builder = client_builder.default_headers(headers); | ||
| } | ||
| } | ||
|
|
||
| Ok(Self { | ||
| listener, | ||
| status, | ||
| github, | ||
| client: Client::builder().redirect(policy).build()?, | ||
| client: client_builder.build()?, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason that private would not need the redirect policy? Otherwise I think you keep the redirect() call here and remove the one at the top. |
||
| path, | ||
| }) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -45,6 +45,40 @@ impl Service { | |||||||
| path, | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /// Build a reqwest request for an asset, handling private/public repos and method. | ||||||||
| fn build_request( | ||||||||
| gh: &GitHub, | ||||||||
| asset: &Asset, | ||||||||
| client: &Client, | ||||||||
| method: &Method, | ||||||||
| ) -> reqwest::RequestBuilder { | ||||||||
| let url = if gh.is_private() { | ||||||||
| format!( | ||||||||
| "https://api.github.com/repos/{}/{}/releases/assets/{}", | ||||||||
| gh.owner(), | ||||||||
| gh.repo(), | ||||||||
| asset.id | ||||||||
| ) | ||||||||
| } else { | ||||||||
| asset.url.clone() | ||||||||
| }; | ||||||||
|
|
||||||||
| match method { | ||||||||
| &Method::HEAD => client.head(url), | ||||||||
| // Only HEAD and GET are expected; all others default to GET. | ||||||||
| _ => client.get(url), | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| fn inspect_response(response: &reqwest::Response) -> (reqwest::StatusCode, Option<&str>) { | ||||||||
| let status_code = response.status(); | ||||||||
| let content_length = response | ||||||||
| .headers() | ||||||||
| .get("content-length") | ||||||||
| .and_then(|v| v.to_str().ok()); | ||||||||
| (status_code, content_length) | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| impl hyper::service::Service<Request<Incoming>> for Service { | ||||||||
|
|
@@ -110,7 +144,21 @@ impl hyper::service::Service<Request<Incoming>> for Service { | |||||||
| None => return Ok(POWEROFF_EFI.reply(None, Type::Efi, EMPTY)), | ||||||||
|
|
||||||||
| // Send the request (possibly redirecting...) | ||||||||
| Some(asset) => (client.head(asset.url).send().await?, asset.mime), | ||||||||
| Some(asset) => { | ||||||||
| let request = | ||||||||
| Self::build_request(&github, &asset, &client, &Method::HEAD); | ||||||||
|
|
||||||||
| match request.send().await { | ||||||||
| Ok(resp) => { | ||||||||
| let (_status_code, _content_length) = | ||||||||
| Self::inspect_response(&resp); | ||||||||
markg-github marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+153
to
+154
|
||||||||
| let (_status_code, _content_length) = | |
| Self::inspect_response(&resp); | |
| // Removed unused inspect_response call |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inspect_response call extracts status code and content length but doesn't use them (indicated by underscore prefix). If these values aren't needed for error handling or logging, consider removing this call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markg-github is there a reason for not removing these? I agree w/ the copilot comments that I can't see why we'd want to inspect the response if nothing is done with the contents. Was this done for debug and then forgot to remove? The original implementation was pretty nice and concise.
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inspect_response function is called but its return values are unused (indicated by the underscore prefix). Consider removing this function call if the values aren't needed, or remove the underscores if they will be used in future iterations.
| let (_status_code, _content_length) = | |
| Self::inspect_response(&resp); | |
| // Removed unused inspect_response call |
Uh oh!
There was an error while loading. Please reload this page.