Skip to content

Commit 93a49e5

Browse files
authored
Merge pull request #1330 from jyn514/shared-pngs
Serve rust-logo.png as a shared file
2 parents ce3f1b8 + ac37c2c commit 93a49e5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/web/rustdoc.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use iron::{
1818
use lol_html::errors::RewritingError;
1919
use router::Router;
2020
use serde::Serialize;
21+
use std::path::Path;
2122

2223
#[derive(Clone)]
2324
pub struct RustLangRedirector {
@@ -644,13 +645,17 @@ impl Handler for SharedResourceHandler {
644645
fn handle(&self, req: &mut Request) -> IronResult<Response> {
645646
let path = req.url.path();
646647
let filename = path.last().unwrap(); // unwrap is fine: vector is non-empty
647-
let suffix = filename.split('.').last().unwrap(); // unwrap is fine: split always works
648-
if ["js", "css", "woff", "svg"].contains(&suffix) {
649-
let storage = extension!(req, Storage);
650-
let config = extension!(req, Config);
648+
if let Some(extension) = Path::new(filename).extension() {
649+
if ["js", "css", "woff", "woff2", "svg", "png"]
650+
.iter()
651+
.any(|s| *s == extension)
652+
{
653+
let storage = extension!(req, Storage);
654+
let config = extension!(req, Config);
651655

652-
if let Ok(file) = File::from_path(&storage, filename, &config) {
653-
return Ok(file.serve());
656+
if let Ok(file) = File::from_path(&storage, filename, &config) {
657+
return Ok(file.serve());
658+
}
654659
}
655660
}
656661

0 commit comments

Comments
 (0)