diff options
author | Quentin <quentin@deuxfleurs.fr> | 2021-01-15 17:03:54 +0100 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2021-01-15 17:03:54 +0100 |
commit | fad7bc405bd8b3cf1dc9a9319a7e3ee0e1eb3461 (patch) | |
tree | 49a05a1c54819865019e7b3e42e57a49d1563505 /src/web | |
parent | 1e10c6a61cf59c11d72e941c5a6d4ea6e159b8ce (diff) | |
download | garage-fad7bc405bd8b3cf1dc9a9319a7e3ee0e1eb3461.tar.gz garage-fad7bc405bd8b3cf1dc9a9319a7e3ee0e1eb3461.zip |
Behavior problem: do not panic anymore + add tests
Diffstat (limited to 'src/web')
-rw-r--r-- | src/web/web_server.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/web/web_server.rs b/src/web/web_server.rs index 25a7cd5f..246c045f 100644 --- a/src/web/web_server.rs +++ b/src/web/web_server.rs @@ -87,9 +87,8 @@ async fn serve_file(garage: Arc<Garage>, req: Request<Body>) -> Result<Response< .ok_or(Error::NotFound)?; match bucket_desc.state.get() { - BucketState::Deleted => Err(Error::NotFound), - BucketState::Present(params) if !params.website.get() => Err(Error::NotFound), - _ => Ok(()), + BucketState::Present(params) if *params.website.get() => Ok(()), + _ => Err(Error::NotFound), }?; // Get path @@ -123,8 +122,10 @@ fn authority_to_host(authority: &str) -> Result<&str, Error> { let split = match first_char { '[' => { let mut iter = iter.skip_while(|(_, c)| c != &']'); - iter.next().expect("Authority parsing logic error"); - iter.next() + match iter.next() { + Some((_, ']')) => iter.next(), + _ => None, + } } _ => iter.skip_while(|(_, c)| c != &':').next(), }; @@ -214,6 +215,10 @@ mod tests { assert_eq!(domain2, "garage.tld"); let domain3 = authority_to_host("127.0.0.1")?; assert_eq!(domain3, "127.0.0.1"); + let domain4 = authority_to_host("[")?; + assert_eq!(domain4, "["); + let domain5 = authority_to_host("[hello")?; + assert_eq!(domain5, "[hello"); Ok(()) } |