Fix redirect
This commit is contained in:
parent
76bf715e55
commit
26c0933341
32
src/main.rs
32
src/main.rs
@ -334,17 +334,31 @@ fn handle_connection(
|
||||
let mut audio_path = path.clone();
|
||||
|
||||
let path = percent_decode_str(relative_path).decode_utf8_lossy();
|
||||
if let Some((path, mut file)) = path.rsplit_once('/') {
|
||||
println!("{path} -> {file}");
|
||||
{
|
||||
let (mut path, mut file) = path.rsplit_once('/').unwrap_or(("", relative_path));
|
||||
let mut redirect = false;
|
||||
|
||||
let replaced_path;
|
||||
if path.contains('_') {
|
||||
let path = path.replace('_', " ");
|
||||
let replaced_file;
|
||||
if !file.contains('.') {
|
||||
replaced_file = file.replace('_', " ");
|
||||
file = &replaced_file;
|
||||
}
|
||||
replaced_path = path.replace('_', " ");
|
||||
path = &replaced_path;
|
||||
redirect = true;
|
||||
}
|
||||
|
||||
let replaced_file;
|
||||
if file.contains('_') && !file.contains('.') {
|
||||
replaced_file = file.replace('_', " ");
|
||||
file = &replaced_file;
|
||||
redirect = true;
|
||||
}
|
||||
|
||||
if redirect {
|
||||
let _ = write!(stream, "HTTP/1.1 308 Permanent Redirect\r\n");
|
||||
let _ = write!(stream, "Location: /{path}/{file}\r\n\r\n");
|
||||
if path.is_empty() {
|
||||
let _ = write!(stream, "Location: /{file}\r\n\r\n");
|
||||
} else {
|
||||
let _ = write!(stream, "Location: /{path}/{file}\r\n\r\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user