mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 20:45:29 +00:00
Minor code cleanup
This commit is contained in:
parent
2213138f50
commit
eaac36c8d6
1 changed files with 19 additions and 25 deletions
16
src/main.rs
16
src/main.rs
|
|
@ -535,9 +535,7 @@ where
|
||||||
// ISOC-RFC 3986, we could use BufRead::read_line here, but that does
|
// ISOC-RFC 3986, we could use BufRead::read_line here, but that does
|
||||||
// not allow us to cap the number of read bytes at 1024+2.
|
// not allow us to cap the number of read bytes at 1024+2.
|
||||||
let result = loop {
|
let result = loop {
|
||||||
let bytes_read = if let Ok(read) = self.stream.read(buf).await {
|
let Ok(bytes_read) = self.stream.read(buf).await else {
|
||||||
read
|
|
||||||
} else {
|
|
||||||
break Err((BAD_REQUEST, "Request ended unexpectedly"));
|
break Err((BAD_REQUEST, "Request ended unexpectedly"));
|
||||||
};
|
};
|
||||||
len += bytes_read;
|
len += bytes_read;
|
||||||
|
|
@ -575,7 +573,9 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// correct host
|
// correct host
|
||||||
if let Some(domain) = url.domain() {
|
let Some(domain) = url.domain() else {
|
||||||
|
return Err((BAD_REQUEST, "URL does not contain a domain"));
|
||||||
|
};
|
||||||
// because the gemini scheme is not special enough for WHATWG, normalize
|
// because the gemini scheme is not special enough for WHATWG, normalize
|
||||||
// it ourselves
|
// it ourselves
|
||||||
let host = Host::parse(
|
let host = Host::parse(
|
||||||
|
|
@ -592,9 +592,6 @@ where
|
||||||
if !ARGS.hostnames.is_empty() && !ARGS.hostnames.iter().any(|h| h == &host) {
|
if !ARGS.hostnames.is_empty() && !ARGS.hostnames.iter().any(|h| h == &host) {
|
||||||
return Err((PROXY_REQUEST_REFUSED, "Proxy request refused"));
|
return Err((PROXY_REQUEST_REFUSED, "Proxy request refused"));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Err((BAD_REQUEST, "URL does not contain a domain"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// correct port
|
// correct port
|
||||||
if let Some(expected_port) = self.local_port_check {
|
if let Some(expected_port) = self.local_port_check {
|
||||||
|
|
@ -737,10 +734,7 @@ where
|
||||||
.add(b'}');
|
.add(b'}');
|
||||||
|
|
||||||
// check if directory listing is enabled by getting preamble
|
// check if directory listing is enabled by getting preamble
|
||||||
let preamble = if let Ok(txt) = std::fs::read_to_string(path.join(".directory-listing-ok"))
|
let Ok(preamble) = std::fs::read_to_string(path.join(".directory-listing-ok")) else {
|
||||||
{
|
|
||||||
txt
|
|
||||||
} else {
|
|
||||||
self.send_header(NOT_FOUND, "Directory index disabled.")
|
self.send_header(NOT_FOUND, "Directory index disabled.")
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue