add_icon_with_headers
This commit is contained in:
parent
f2efe51c22
commit
0bead553c2
4 changed files with 17 additions and 4 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1513,7 +1513,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
|
|||
|
||||
[[package]]
|
||||
name = "site_icons"
|
||||
version = "0.1.13"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"clap",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "site_icons"
|
||||
version = "0.1.13"
|
||||
version = "0.2.0"
|
||||
authors = ["Sam Denty <sam@samdenty.com>"]
|
||||
edition = "2018"
|
||||
license = "GPL-3.0"
|
||||
|
|
|
@ -32,6 +32,7 @@ pub enum IconInfo {
|
|||
impl IconInfo {
|
||||
pub async fn load(
|
||||
url: Url,
|
||||
headers: HeaderMap,
|
||||
sizes: Option<String>,
|
||||
) -> Result<IconInfo, Box<dyn Error>> {
|
||||
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());
|
||||
};
|
||||
|
|
14
src/icons.rs
14
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<String>) {
|
||||
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<String>,
|
||||
) {
|
||||
// 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();
|
||||
|
|
Reference in a new issue