Skip to content

Commit

Permalink
clippy::single-match-else
Browse files Browse the repository at this point in the history
  • Loading branch information
eopb committed May 21, 2020
1 parent 2b50af0 commit 9cfbea4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
11 changes: 5 additions & 6 deletions src/fs/serve_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ impl<State> Endpoint<State> for ServeDir {
Ok(file) => file,
};

let len = match file.metadata().await {
Ok(metadata) => metadata.len() as usize,
Err(_) => {
log::warn!("Could not retrieve metadata");
return Ok(Response::new(StatusCode::InternalServerError));
}
let len = if let Ok(metadata) = file.metadata().await {
metadata.len() as usize
} else {
log::warn!("Could not retrieve metadata");
return Ok(Response::new(StatusCode::InternalServerError));
};

let body = Body::from_reader(BufReader::new(file), Some(len));
Expand Down
11 changes: 5 additions & 6 deletions src/security/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,11 @@ impl<State: Send + Sync + 'static> Middleware<State> for CorsMiddleware {
let origins = req.header(&headers::ORIGIN).cloned().unwrap_or_default();

// TODO: how should multiple origin values be handled?
let origin = match origins.first() {
Some(origin) => origin,
None => {
// This is not a CORS request if there is no Origin header
return next.run(req).await;
}
let origin = if let Some(origin) = origins.first() {
origin
} else {
// This is not a CORS request if there is no Origin header
return next.run(req).await;
};

if !self.is_valid_origin(origin) {
Expand Down

0 comments on commit 9cfbea4

Please sign in to comment.