aboutsummaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
authorQuentin <quentin@deuxfleurs.fr>2020-11-10 15:48:40 +0100
committerQuentin <quentin@deuxfleurs.fr>2020-11-10 15:48:40 +0100
commitd1b2fcc1e7d54025625c62bff7ef8cb573fab456 (patch)
tree4576ce88288fe9dc2601a2e4ec3952d4657c8bff /src/web
parentab62c59acb49d1f3563d546eb6af13bf40739c2f (diff)
downloadgarage-d1b2fcc1e7d54025625c62bff7ef8cb573fab456.tar.gz
garage-d1b2fcc1e7d54025625c62bff7ef8cb573fab456.zip
Rewrite for clarity
Diffstat (limited to 'src/web')
-rw-r--r--src/web/web_server.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/web/web_server.rs b/src/web/web_server.rs
index cda7f52e..e4d15872 100644
--- a/src/web/web_server.rs
+++ b/src/web/web_server.rs
@@ -66,21 +66,24 @@ async fn handler(
///
/// The HTTP host contains both a host and a port.
/// Extracting the port is more complex than just finding the colon (:) symbol due to IPv6
-/// we do not use the collect pattern as there is no way in std rust to collect over a stack allocated value
+/// We do not use the collect pattern as there is no way in std rust to collect over a stack allocated value
/// check here: https://docs.rs/collect_slice/1.2.0/collect_slice/
fn authority_to_host(authority: &str) -> Result<&str, Error> {
let mut iter = authority.chars().enumerate();
- let split = match iter.next() {
- Some((_, '[')) => {
- let mut niter = iter.skip_while(|(_, c)| c != &']');
- niter.next().ok_or(Error::BadRequest(format!(
+ let (_, first_char) = iter
+ .next()
+ .ok_or(Error::BadRequest(format!("Authority is empty")))?;
+
+ let split = match first_char {
+ '[' => {
+ let mut iter = iter.skip_while(|(_, c)| c != &']');
+ iter.next().ok_or(Error::BadRequest(format!(
"Authority {} has an illegal format",
authority
)))?;
- niter.next()
+ iter.next()
}
- Some((_, _)) => iter.skip_while(|(_, c)| c != &':').next(),
- None => return Err(Error::BadRequest(format!("Authority is empty"))),
+ _ => iter.skip_while(|(_, c)| c != &':').next(),
};
match split {