mirror of
https://github.com/samsonjs/agate.git
synced 2026-03-25 09:05:50 +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
|
||||
// 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,25 +573,24 @@ where
|
|||
}
|
||||
|
||||
// correct host
|
||||
if let Some(domain) = url.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"));
|
||||
}
|
||||
} else {
|
||||
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(
|
||||
&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
|
||||
|
|
@ -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(());
|
||||
|
|
|
|||
Loading…
Reference in a new issue