From 07d5563ecd7037b2b246f6b505f5a93d094ebf7b Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Mon, 7 Oct 2024 11:02:31 -0700 Subject: [PATCH] fix(deno-embed): accept github token to increase rate limits --- packages/deno-embed/build.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/deno-embed/build.rs b/packages/deno-embed/build.rs index b584d982..f4d499e0 100644 --- a/packages/deno-embed/build.rs +++ b/packages/deno-embed/build.rs @@ -39,10 +39,13 @@ fn fetch_release_data() -> Result> { println!("Fetching release information from: {}", release_url); let client = Client::new(); - let response = client - .get(&release_url) - .header(reqwest::header::USER_AGENT, USER_AGENT) - .send()?; + let mut request = client.get(&release_url).header(reqwest::header::USER_AGENT, USER_AGENT); + + if let Ok(token) = env::var("GITHUB_TOKEN") { + request = request.header(reqwest::header::AUTHORIZATION, format!("token {}", token)); + } + + let response = request.send()?; let status = response.status(); if !status.is_success() { let error_text = response.text()?; @@ -93,11 +96,13 @@ fn download_binary_if_needed( println!("Downloading Deno binary from: {}", download_url); let client = Client::new(); - let response = client - .get(download_url) - .header(reqwest::header::USER_AGENT, USER_AGENT) - .send()? - .error_for_status()?; + let mut request = client.get(download_url).header(reqwest::header::USER_AGENT, USER_AGENT); + + if let Ok(token) = env::var("GITHUB_TOKEN") { + request = request.header(reqwest::header::AUTHORIZATION, format!("token {}", token)); + } + + let response = request.send()?.error_for_status()?; let mut file = fs::File::create(&zip_path)?; std::io::copy(&mut response.bytes()?.as_ref(), &mut file)?;