From 6850b73fc0f57ebd3417a4a4b5277ec89ae4fc69 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 6 May 2021 21:18:42 -0700 Subject: fix(utils): conditional authorization header placement Usefull when deploying with Docker. --- src/utils.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index ac1b51d..3d40e7c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -7,17 +7,22 @@ use crate::{ }; pub async fn github_api() -> Result> { + let mut client = actix_web::client::Client::new() + .get(GITHUB_API_ENDPOINT) + .header("User-Agent", USER_AGENT); + + if std::env::var("GITHUB_TOKEN").is_ok() { + client = client.header( + "Authorization", + format!( + "token {}", + std::env::var("GITHUB_TOKEN").unwrap_or_else(|_| "Null".to_string()) + ), + ); + } + Ok( - actix_web::client::Client::new() - .get(GITHUB_API_ENDPOINT) - .header("User-Agent", USER_AGENT) - .header( - "Authorization", - format!( - "token {}", - std::env::var("GITHUB_TOKEN").unwrap_or_else(|_| "Null".to_string()) - ), - ) + client .timeout(std::time::Duration::from_secs(60)) .send() .await? -- cgit v1.2.3