From 261c8b6ee57458c2ebb3f266ee4f7eb59482394b Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 7 Jun 2022 08:59:44 +0800 Subject: [PATCH] feat: add favicon (#27) Return favicon only if requested, avoid 404 errors close #16 --- assets/favicon.ico | Bin 0 -> 4286 bytes src/server.rs | 7 +++++++ 2 files changed, 7 insertions(+) create mode 100755 assets/favicon.ico diff --git a/assets/favicon.ico b/assets/favicon.ico new file mode 100755 index 0000000000000000000000000000000000000000..57d35312ae127d7e47a30bd9786acc8d256f14fc GIT binary patch literal 4286 zcmeH~ZAhe56vxjqGmegqj&D2T%jk?Ly1u_pq>c&|+XqQfDF~%t^TR;ME{QO?$U;Se z5JW*iUj&J5BajgM62Y+3LbRXuOIu$yH!|9&*d=wLTAzOB$q@}_nw4n@+ADvbd(XZ1 z{Lel2+;i`U82kl;qW|TCLJ_ZsoCJtu7^vJT^!=C1UpP#>e0H>&@OS?Y~Ug_!SaWVHjo6WXM zhiMpwsb2+l-1PZ;qdFlHiCDJco3O*-*iMYu`<~V@_gY*omz0*4K4G`px0q|P{x1s) z3+J)tEo8S;mXnin89R&X>+3VhKQ}jLnd^4DUsoR1f5+?fj;U~VcGiyk9hGCpuh=-? z@pv-IKQb~R@p#-|eeWv|zW%PJrluAMdmse`1<&bTfZgKa;%D)BM)_M?TV;HF+y?JO z<;RYVuCA^?cXzi?my(i_r}4>MwE_Oq)HBN8($XShV`GQ-J3Bj%M&qx& zy>c*SS07Z!S^-35#*1Mqw?4vSzBAP%udEn zjNIn#`XL2=r0+9u0vvJy_sV(Au?Y8}ZDR5^Z-9@9g^*6re4UJ+d-NQ+vkrStrocn= zIlv)))_NX+-ZOXMyvka>05@q{?*ZceD{SaRmXx3Q$GZR3kOV*aw*!H|;Jd&$eH(6*hack}IFg?` zBXW3@`^C}G(UG7(82>xf)zza_RaIVMt&2SLCcJl)AN_HC1Ji#bzm7=-tshm( z%gfeywEJX!o7z9F_c%!pG9&&)c^nh literal 0 HcmV?d00001 diff --git a/src/server.rs b/src/server.rs index cda0804..bf89df0 100644 --- a/src/server.rs +++ b/src/server.rs @@ -44,6 +44,7 @@ type Response = hyper::Response; const INDEX_HTML: &str = include_str!("../assets/index.html"); const INDEX_CSS: &str = include_str!("../assets/index.css"); const INDEX_JS: &str = include_str!("../assets/index.js"); +const FAVICON_ICO: &[u8] = include_bytes!("../assets/favicon.ico"); const INDEX_NAME: &str = "index.html"; const BUF_SIZE: usize = 1024 * 16; @@ -174,6 +175,12 @@ impl InnerService { status!(res, StatusCode::NOT_FOUND); return Ok(res); } + if is_miss && path.ends_with("favicon.ico") { + *res.body_mut() = Body::from(FAVICON_ICO); + res.headers_mut() + .insert("content-type", "image/x-icon".parse().unwrap()); + return Ok(res); + } let headers = req.headers();