Allow all image paths, only care about the ending
This commit is contained in:
parent
4519c5c7ab
commit
bba2c0a4f0
27
src/main.rs
27
src/main.rs
@ -199,9 +199,14 @@ fn handle_connection(context: Arc<Mutex<Context>>, path: PathBuf, mut stream: Tc
|
||||
(Some(pki_path), 1, path.to_string(), num)
|
||||
};
|
||||
|
||||
if relative_path.split('/').any(|name| name == "Images") {
|
||||
if let Some((_, ending)) = relative_path.rsplit_once('.') {
|
||||
let path = path.to_path_buf();
|
||||
reply_image(stream, &relative_path, path);
|
||||
let ending = ending.to_lowercase();
|
||||
match ending.as_ref() {
|
||||
"jpg" => reply_image(stream, &relative_path, "jpeg", path),
|
||||
"png" | "tiff" | "gif" | "jpeg" => reply_image(stream, &relative_path, &ending, path),
|
||||
_ => fail(stream),
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
@ -251,23 +256,7 @@ fn handle_connection(context: Arc<Mutex<Context>>, path: PathBuf, mut stream: Tc
|
||||
)
|
||||
}
|
||||
|
||||
fn reply_image(mut stream: TcpStream, relative_path: &str, mut path: PathBuf) {
|
||||
let Some((_, ending)) = relative_path.rsplit_once('.') else {
|
||||
fail(stream);
|
||||
return;
|
||||
};
|
||||
|
||||
let ending = ending.to_lowercase();
|
||||
|
||||
let image_type = match ending.as_ref() {
|
||||
"jpg" => "jpeg",
|
||||
"png" | "tiff" | "gif" | "jpeg" => &ending,
|
||||
_ => {
|
||||
fail(stream);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
fn reply_image(mut stream: TcpStream, relative_path: &str, image_type: &str, mut path: PathBuf) {
|
||||
path.push(relative_path);
|
||||
let Ok(mut file) = File::open(path) else {
|
||||
fail(stream);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user