aboutsummaryrefslogtreecommitdiff
path: root/src/web/web_server.rs
diff options
context:
space:
mode:
authorTrinity Pointard <trinity.pointard@gmail.com>2021-04-23 22:26:27 +0200
committerAlex Auvolat <alex@adnab.me>2021-05-03 22:11:42 +0200
commitf8ae8fc4beba57f1fb391f6fc9f38e6ab59406a9 (patch)
tree3f119e78410a85841fcad10955809c469f88e855 /src/web/web_server.rs
parent84856e84e5c7ccbb6cb32582c1ef71acc83396f5 (diff)
downloadgarage-f8ae8fc4beba57f1fb391f6fc9f38e6ab59406a9.tar.gz
garage-f8ae8fc4beba57f1fb391f6fc9f38e6ab59406a9.zip
fix clippy warnings on web
Diffstat (limited to 'src/web/web_server.rs')
-rw-r--r--src/web/web_server.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/web/web_server.rs b/src/web/web_server.rs
index 9635eca6..babde62a 100644
--- a/src/web/web_server.rs
+++ b/src/web/web_server.rs
@@ -71,7 +71,7 @@ async fn serve_file(garage: Arc<Garage>, req: Request<Body>) -> Result<Response<
let authority = req
.headers()
.get(HOST)
- .ok_or(Error::BadRequest(format!("HOST header required")))?
+ .ok_or_else(|| Error::BadRequest("HOST header required".to_owned()))?
.to_str()?;
// Get bucket
@@ -99,10 +99,10 @@ async fn serve_file(garage: Arc<Garage>, req: Request<Body>) -> Result<Response<
info!("Selected bucket: \"{}\", selected key: \"{}\"", bucket, key);
- let res = match req.method() {
- &Method::HEAD => handle_head(garage, &req, &bucket, &key).await?,
- &Method::GET => handle_get(garage, &req, bucket, &key).await?,
- _ => return Err(Error::BadRequest(format!("HTTP method not supported"))),
+ let res = match *req.method() {
+ Method::HEAD => handle_head(garage, &req, &bucket, &key).await?,
+ Method::GET => handle_get(garage, &req, bucket, &key).await?,
+ _ => return Err(Error::BadRequest("HTTP method not supported".to_string())),
};
Ok(res)
@@ -118,7 +118,7 @@ fn authority_to_host(authority: &str) -> Result<&str, Error> {
let mut iter = authority.chars().enumerate();
let (_, first_char) = iter
.next()
- .ok_or(Error::BadRequest(format!("Authority is empty")))?;
+ .ok_or_else(|| Error::BadRequest("Authority is empty".to_string()))?;
let split = match first_char {
'[' => {
@@ -133,7 +133,7 @@ fn authority_to_host(authority: &str) -> Result<&str, Error> {
}
}
}
- _ => iter.skip_while(|(_, c)| c != &':').next(),
+ _ => iter.find(|(_, c)| *c == ':'),
};
match split {
@@ -158,7 +158,7 @@ fn host_to_bucket<'a>(host: &'a str, root: &str) -> &'a str {
}
let len_diff = host.len() - root.len();
- let missing_starting_dot = root.chars().next() != Some('.');
+ let missing_starting_dot = !root.starts_with('.');
let cursor = if missing_starting_dot {
len_diff - 1
} else {
@@ -175,10 +175,10 @@ fn host_to_bucket<'a>(host: &'a str, root: &str) -> &'a str {
fn path_to_key<'a>(path: &'a str, index: &str) -> Result<Cow<'a, str>, Error> {
let path_utf8 = percent_encoding::percent_decode_str(&path).decode_utf8()?;
- if path_utf8.chars().next() != Some('/') {
- return Err(Error::BadRequest(format!(
- "Path must start with a / (slash)"
- )));
+ if !path_utf8.starts_with('/') {
+ return Err(Error::BadRequest(
+ "Path must start with a / (slash)".to_string(),
+ ));
}
match path_utf8.chars().last() {