Browse Source
Merge pull request #1545 from RealOrangeOne/icon-client-cache
Client caching
pull/1552/head
Daniel García
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
11 additions and
7 deletions
-
src/api/icons.rs
-
src/util.rs
|
@ -51,7 +51,7 @@ fn icon(domain: String) -> Option<Cached<Content<Vec<u8>>>> { |
|
|
return None; |
|
|
return None; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
get_icon(&domain).map(|icon| Cached::long(Content(ContentType::new("image", "x-icon"), icon))) |
|
|
get_icon(&domain).map(|icon| Cached::ttl(Content(ContentType::new("image", "x-icon"), icon), CONFIG.icon_cache_ttl())) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// Returns if the domain provided is valid or not.
|
|
|
/// Returns if the domain provided is valid or not.
|
|
@ -472,7 +472,7 @@ fn get_icon_url(domain: &str) -> Result<IconUrlResult, Error> { |
|
|
let dom = html5ever::parse_document(markup5ever_rcdom::RcDom::default(), Default::default()) |
|
|
let dom = html5ever::parse_document(markup5ever_rcdom::RcDom::default(), Default::default()) |
|
|
.from_utf8() |
|
|
.from_utf8() |
|
|
.read_from(&mut limited_reader)?; |
|
|
.read_from(&mut limited_reader)?; |
|
|
|
|
|
|
|
|
get_favicons_node(&dom.document, &mut iconlist, &url); |
|
|
get_favicons_node(&dom.document, &mut iconlist, &url); |
|
|
} else { |
|
|
} else { |
|
|
// Add the default favicon.ico to the list with just the given domain
|
|
|
// Add the default favicon.ico to the list with just the given domain
|
|
|
|
@ -92,17 +92,21 @@ impl Fairing for CORS { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub struct Cached<R>(R, &'static str); |
|
|
pub struct Cached<R>(R, String); |
|
|
|
|
|
|
|
|
impl<R> Cached<R> { |
|
|
impl<R> Cached<R> { |
|
|
pub const fn long(r: R) -> Cached<R> { |
|
|
pub fn long(r: R) -> Cached<R> { |
|
|
// 7 days
|
|
|
// 7 days
|
|
|
Self(r, "public, max-age=604800") |
|
|
Self::ttl(r, 604800) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub const fn short(r: R) -> Cached<R> { |
|
|
pub fn short(r: R) -> Cached<R> { |
|
|
// 10 minutes
|
|
|
// 10 minutes
|
|
|
Self(r, "public, max-age=600") |
|
|
Self(r, String::from("public, max-age=600")) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn ttl(r: R, ttl: u64) -> Cached<R> { |
|
|
|
|
|
Self(r, format!("public, immutable, max-age={}", ttl)) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|