Skip to content

Commit

Permalink
Fix long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jespersm committed Sep 20, 2023
1 parent 7251c5b commit bad92b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions core/lib/src/router/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::http::{Method, Status};
use crate::{Route, Catcher};
use crate::router::Collide;

use super::matcher::{paths_match, queries_match};

#[derive(Debug, Default)]
pub(crate) struct Router {
routes: HashMap<Method, Vec<Route>>,
Expand Down Expand Up @@ -62,7 +64,7 @@ impl Router {
self.routes.get(&req.method())
.into_iter()
.flatten()
.any(|route| super::matcher::paths_match(route, req) && super::matcher::queries_match(route, req))
.any(|route| paths_match(route, req) && queries_match(route, req))
}

const ALL_METHODS: &[Method] = &[
Expand All @@ -79,7 +81,7 @@ impl Router {
.filter(|method| *method != &req.method())
.filter_map(|method| self.routes.get(method))
.flatten()
.any(|route| super::matcher::paths_match(route, req))
.any(|route| paths_match(route, req))
}

// For many catchers, using aho-corasick or similar should be much faster.
Expand Down
10 changes: 7 additions & 3 deletions core/lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,16 @@ impl Rocket<Orbit> {

error_!("No matching routes for {}.", request);
if request.route().is_none() {
// We failed to find a route which matches on path, query AND formats
// We failed to find a route which matches on path, query AND formats.
if self.router.matches_except_formats(request) {
// Tailor the error code to the interpretation of the request in question.
status = if request.method().supports_payload() { Status::UnsupportedMediaType } else { Status::NotAcceptable };
if request.method().supports_payload() {
status = Status::UnsupportedMediaType;
} else {
status = Status::NotAcceptable;
}
} else if self.router.matches_except_method(request) {
// Found a more suitable error code from simple route paths implemented on different methods
// Found a more suitable error code for paths implemented on different methods.
status = Status::MethodNotAllowed;
}
}
Expand Down

0 comments on commit bad92b4

Please sign in to comment.