Skip to content

fixes #1409: internal server error with two slashes at the end of the URL #1410

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

Merged
merged 2 commits into from
Jun 5, 2021

Conversation

syphar
Copy link
Member

@syphar syphar commented May 30, 2021

When iron finds a slash at the end of the route if will try to redirect if the route exists without the slash in the end.
This leads to an IronError which contains a normal permanent redirect as response.

This is no error for us, we can just return Ok(error.response) for these cases.

@syphar syphar self-assigned this May 30, 2021
src/web/mod.rs Outdated
if e.error.downcast_ref::<TrailingSlash>().is_some()
|| e.response.status == Some(status::MovedPermanently)
{
Ok(e.response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why will there still be a response if there's an error? Also, why does this also handle MovedPermanently? That seems like a change in behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow.

In our own code we do redirects by returning an Ok(Response). Our code expects this and passes this through.

For this specific case (URL without slash at the end has a match, see the iron source), iron returns an IronError(Response).

Since for us the redirect is fine, and not an error, I want to convert this.

( of course I could be missing something)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I see - we have our own error handler on top of iron's built-in error handlers. And our error handler expects to recognized every possible error, that's what the last or_else on line 197 is doing. Since iron has its own built-in error handlers, some of its errors (but not ours) will actually be valid HTTP responses that we can serve without changes.

@jyn514 jyn514 merged commit ba9364b into rust-lang:master Jun 5, 2021
@syphar syphar deleted the fix_double_slash branch June 19, 2021 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants