From f024cc664929b167060493784124782e65e60461 Mon Sep 17 00:00:00 2001 From: Shreyan Bag Date: Sun, 22 Nov 2026 14:40:18 +0530 Subject: [PATCH] Skip the Authorization header when the GitHub API token is empty The update check calls the releases API anonymously with an empty token, but the header was always sent as "Bearer " with nothing after it, which GitHub rejects with 401. Only send the header when a token is present. Co-Authored-By: Claude Opus 5.5 --- crates/core/src/github.rs | 40 +++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/crates/core/src/github.rs b/crates/core/src/github.rs index 5e73b5a..6894698 100644 --- a/crates/core/src/github.rs +++ b/crates/core/src/github.rs @@ -131,21 +131,33 @@ impl Http for UreqHttp { token: &str, body: Option<&str>, ) -> Result<(u16, String), GithubError> { - let authorization: String = format!("Bearer {token}"); + // An empty token means an anonymous request (e.g. the public release + // check). Sending `Authorization: Bearer ` with nothing after it makes + // GitHub answer 401, so the header is only added when there is a token. + let authorization: Option = + (!token.trim().is_empty()).then(|| format!("Bearer {}", token.trim())); let response = match (method, body) { - ("POST", Some(body)) => self - .agent - .post(url) - .header("Authorization", &authorization) - .header("Accept", "application/vnd.github+json") - .header("Content-Type", "application/json") - .send(body), - _ => self - .agent - .get(url) - .header("Authorization", &authorization) - .header("Accept", "application/vnd.github+json") - .call(), + ("POST", Some(body)) => { + let mut request = self + .agent + .post(url) + .header("Accept", "application/vnd.github+json") + .header("Content-Type", "application/json"); + if let Some(authorization) = &authorization { + request = request.header("Authorization", authorization); + } + request.send(body) + } + _ => { + let mut request = self + .agent + .get(url) + .header("Accept", "application/vnd.github+json"); + if let Some(authorization) = &authorization { + request = request.header("Authorization", authorization); + } + request.call() + } } .map_err(|error| GithubError::Network(error.to_string()))?; read_body(response)