From 0bead553c269e5895952dbce2904337f11dd44b8 Mon Sep 17 00:00:00 2001 From: Sam Denty Date: Sat, 1 Oct 2022 21:57:23 +0100 Subject: [PATCH] add_icon_with_headers --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/icon_info.rs | 3 ++- src/icons.rs | 14 +++++++++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5b49c1..c0f342b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1513,7 +1513,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" [[package]] name = "site_icons" -version = "0.1.13" +version = "0.2.0" dependencies = [ "byteorder", "clap", diff --git a/Cargo.toml b/Cargo.toml index ac5613c..ca8c327 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "site_icons" -version = "0.1.13" +version = "0.2.0" authors = ["Sam Denty "] edition = "2018" license = "GPL-3.0" diff --git a/src/icon_info.rs b/src/icon_info.rs index b07aeba..e1894dc 100644 --- a/src/icon_info.rs +++ b/src/icon_info.rs @@ -32,6 +32,7 @@ pub enum IconInfo { impl IconInfo { pub async fn load( url: Url, + headers: HeaderMap, sizes: Option, ) -> Result> { let sizes = sizes.as_ref().and_then(|s| IconSizes::from_str(s).ok()); @@ -54,7 +55,7 @@ impl IconInfo { } _ => { - let res = CLIENT.get(url).send().await?; + let res = CLIENT.get(url).headers(headers).send().await?; if !res.status().is_success() { return Err("failed to fetch".into()); }; diff --git a/src/icons.rs b/src/icons.rs index ec4fed6..4b6c45b 100644 --- a/src/icons.rs +++ b/src/icons.rs @@ -46,6 +46,18 @@ impl Icons { /// Add an icon URL and start fetching it pub fn add_icon(&mut self, url: Url, kind: IconKind, sizes: Option) { + self.add_icon_with_headers(url, HeaderMap::new(), kind, sizes) + } + + /// Add an icon URL and start fetching it, + /// along with the specified headers + pub fn add_icon_with_headers( + &mut self, + url: Url, + headers: HeaderMap, + kind: IconKind, + sizes: Option, + ) { // check to see if it already exists let mut entries = self.entries.iter_mut(); if let Some(existing_kind) = self @@ -69,7 +81,7 @@ impl Icons { return; } - let mut info = Box::pin(IconInfo::load(url.clone(), sizes)); + let mut info = Box::pin(IconInfo::load(url.clone(), headers, sizes)); // Start fetching the icon let noop_waker = noop_waker();