Skip to content

Commit

Permalink
Merge branch 'trunk' into feature/doc
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Nov 14, 2024
2 parents 03fedb2 + d405597 commit 559522f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ smoltcp = { version = "0.11.0", default-features = false, features = ["alloc", "
spin = "0.9.8"
time = { version = "0.2.27", default-features = false }
geodate = { version = "0.5.0", default-features = false }
uart_16550 = "0.3.1"
uart_16550 = "0.3.2"
vte = "0.13.0"
x86_64 = "0.15.1"

Expand Down
28 changes: 10 additions & 18 deletions src/usr/httpd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn get(req: &Request, res: &mut Response) {
"Location".to_string(),
format!("{}/", req.path),
);
res.body.extend_from_slice(b"<h1>Moved Permanently</h1>\r\n");
res.body.extend_from_slice(b"<h1>Moved Permanently</h1>\n");
} else {
let mut not_found = true;
for index in INDEX {
Expand All @@ -221,16 +221,7 @@ fn get(req: &Request, res: &mut Response) {
if let Ok(buf) = fs::read_to_bytes(&real_path) {
res.code = 200;
res.mime = content_type(&real_path);
let tmp;
res.body.extend_from_slice(
if res.mime.starts_with("text/") {
tmp = String::from_utf8_lossy(&buf).to_string().
replace("\n", "\r\n");
tmp.as_bytes()
} else {
&buf
},
);
res.body.extend_from_slice(&buf);
not_found = false;
break;
}
Expand All @@ -240,22 +231,22 @@ fn get(req: &Request, res: &mut Response) {
res.code = 200;
res.mime = "text/html".to_string();
res.body.extend_from_slice(
format!("<h1>Index of {}</h1>\r\n", req.path).as_bytes()
format!("<h1>Index of {}</h1>\n", req.path).as_bytes()
);
files.sort_by_key(|f| f.name());
for file in files {
let path = format!("{}{}", req.path, file.name());
let path = format!(
"{}{}", req.path, file.name()
);
let link = format!(
"<li><a href=\"{}\">{}</a></li>\n",
path,
file.name()
"<li><a href=\"{}\">{}</a></li>\n", path, file.name()
);
res.body.extend_from_slice(link.as_bytes());
}
} else {
res.code = 404;
res.mime = "text/html".to_string();
res.body.extend_from_slice(b"<h1>Not Found</h1>\r\n");
res.body.extend_from_slice(b"<h1>Not Found</h1>\n");
}
}
}
Expand Down Expand Up @@ -413,7 +404,7 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
delete(&req, &mut res)
}
_ => {
let s = b"<h1>Bad Request</h1>\r\n";
let s = b"<h1>Bad Request</h1>\n";
res.body.extend_from_slice(s);
res.code = 400;
res.mime = "text/html".to_string();
Expand Down Expand Up @@ -467,6 +458,7 @@ pub fn main(args: &[&str]) -> Result<(), ExitCode> {
fn content_type(path: &str) -> String {
let ext = path.rsplit_once('.').unwrap_or(("", "")).1;
match ext {
"bmp" => "image/bmp",
"css" => "text/css",
"csv" => "text/csv",
"gif" => "text/gif",
Expand Down

0 comments on commit 559522f

Please sign in to comment.