Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve rust-logo.png as a shared file #1330

Merged
merged 2 commits into from
Mar 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use iron::{
use lol_html::errors::RewritingError;
use router::Router;
use serde::Serialize;
use std::path::Path;

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

if let Ok(file) = File::from_path(&storage, filename, &config) {
return Ok(file.serve());
if let Ok(file) = File::from_path(&storage, filename, &config) {
return Ok(file.serve());
}
}
}

Expand Down