-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1224 by searching routes after failed match #2616
base: master
Are you sure you want to change the base?
Changes from all commits
7251c5b
bad92b4
8faaff9
2a2272e
35669cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -342,6 +342,20 @@ 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. | ||
if self.router.matches_except_formats(request) { | ||
// Tailor the error code to the interpretation of the request in question. | ||
if request.method().supports_payload() { | ||
status = Status::UnsupportedMediaType; | ||
} else { | ||
status = Status::NotAcceptable; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t think that returning IMHO this branch should always return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite follow your reasoning here. Rocket's route "format" specifier switches on exactly whether or not the method expects payload or not ( https://rocket.rs/v0.5/guide/requests/#format ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, I didn’t realize that this restriction had different meanings depending on the method. Your implementation is correct. |
||
} else if self.router.matches_except_method(request) { | ||
// Found a more suitable error code for paths implemented on different methods. | ||
status = Status::MethodNotAllowed; | ||
} | ||
} | ||
Outcome::Forward((data, status)) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to simplify this using the
Router::routes
method:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll check how that works out.