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
44
src/main.rs
44
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,25 +573,24 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// correct host
|
// correct host
|
||||||
if let Some(domain) = url.domain() {
|
let Some(domain) = url.domain() else {
|
||||||
// because the gemini scheme is not special enough for WHATWG, normalize
|
|
||||||
// it ourselves
|
|
||||||
let host = Host::parse(
|
|
||||||
&percent_decode_str(domain)
|
|
||||||
.decode_utf8()
|
|
||||||
.or(Err((BAD_REQUEST, "Invalid URL")))?,
|
|
||||||
)
|
|
||||||
.or(Err((BAD_REQUEST, "Invalid URL")))?;
|
|
||||||
// TODO: simplify when <https://github.com/servo/rust-url/issues/586> resolved
|
|
||||||
url.set_host(Some(&host.to_string()))
|
|
||||||
.expect("invalid domain?");
|
|
||||||
// do not use "contains" here since it requires the same type and does
|
|
||||||
// not allow to check for Host<&str> if the vec contains Hostname<String>
|
|
||||||
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"));
|
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(
|
||||||
|
&percent_decode_str(domain)
|
||||||
|
.decode_utf8()
|
||||||
|
.or(Err((BAD_REQUEST, "Invalid URL")))?,
|
||||||
|
)
|
||||||
|
.or(Err((BAD_REQUEST, "Invalid URL")))?;
|
||||||
|
// TODO: simplify when <https://github.com/servo/rust-url/issues/586> resolved
|
||||||
|
url.set_host(Some(&host.to_string()))
|
||||||
|
.expect("invalid domain?");
|
||||||
|
// do not use "contains" here since it requires the same type and does
|
||||||
|
// not allow to check for Host<&str> if the vec contains Hostname<String>
|
||||||
|
if !ARGS.hostnames.is_empty() && !ARGS.hostnames.iter().any(|h| h == &host) {
|
||||||
|
return Err((PROXY_REQUEST_REFUSED, "Proxy request refused"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// correct port
|
// correct port
|
||||||
|
|
@ -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