Minor code cleanup

This commit is contained in:
Matt Brubeck 2023-12-20 17:23:01 -08:00
parent 2213138f50
commit eaac36c8d6

View file

@ -535,9 +535,7 @@ where
// 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.
let result = loop {
let bytes_read = if let Ok(read) = self.stream.read(buf).await {
read
} else {
let Ok(bytes_read) = self.stream.read(buf).await else {
break Err((BAD_REQUEST, "Request ended unexpectedly"));
};
len += bytes_read;
@ -575,7 +573,9 @@ where
}
// 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
// it ourselves
let host = Host::parse(
@ -592,9 +592,6 @@ where
if !ARGS.hostnames.is_empty() && !ARGS.hostnames.iter().any(|h| h == &host) {
return Err((PROXY_REQUEST_REFUSED, "Proxy request refused"));
}
} else {
return Err((BAD_REQUEST, "URL does not contain a domain"));
}
// correct port
if let Some(expected_port) = self.local_port_check {
@ -737,10 +734,7 @@ where
.add(b'}');
// 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"))
{
txt
} else {
let Ok(preamble) = std::fs::read_to_string(path.join(".directory-listing-ok")) else {
self.send_header(NOT_FOUND, "Directory index disabled.")
.await?;
return Ok(());