Changed how binary replies work
This commit is contained in:
parent
4dc33e8c60
commit
6fa0e14469
16
src/main.rs
16
src/main.rs
@ -325,8 +325,10 @@ fn handle_connection(
|
||||
let path = path.to_path_buf();
|
||||
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),
|
||||
"jpg" => reply_binary(stream, &relative_path, "image", "jpeg", path),
|
||||
"png" | "tiff" | "gif" | "jpeg" => {
|
||||
reply_binary(stream, &relative_path, "image", &ending, path)
|
||||
}
|
||||
_ => fail(stream),
|
||||
};
|
||||
return;
|
||||
@ -378,7 +380,13 @@ fn handle_connection(
|
||||
)
|
||||
}
|
||||
|
||||
fn reply_image(mut stream: TcpStream, relative_path: &str, image_type: &str, mut path: PathBuf) {
|
||||
fn reply_binary(
|
||||
mut stream: TcpStream,
|
||||
relative_path: &str,
|
||||
data_type: &str,
|
||||
file_type: &str,
|
||||
mut path: PathBuf,
|
||||
) {
|
||||
path.push(relative_path);
|
||||
let Ok(mut file) = File::open(path) else {
|
||||
fail(stream);
|
||||
@ -386,7 +394,7 @@ fn reply_image(mut stream: TcpStream, relative_path: &str, image_type: &str, mut
|
||||
};
|
||||
|
||||
let _ = write!(stream, "HTTP/1.1 200 OK\r\n");
|
||||
let _ = write!(stream, "Content-Type: image/{image_type}\r\n");
|
||||
let _ = write!(stream, "Content-Type: {data_type}/{file_type}\r\n");
|
||||
let _ = write!(stream, "\r\n");
|
||||
|
||||
let mut buf = [0; 0x400];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user