Skip to content
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

Treat PSR-7 request conversions as route failures #13

Merged
merged 4 commits into from
Jan 6, 2022

Conversation

weierophinney
Copy link
Contributor

This patch adds a try/catch block within the LaminasRouter::match() method around the conversion of the PSR-7 request to a laminas-http request. It catches laminas-http InvalidArgumentExceptions, and checks for a previous exception matching a laminas-http InvalidUriPartException. When detected, it returns a RouteResult indicating a routing failure; otherwise, it rethrows the exception.

The patch is intended to fix scenarios where the Host header is invalid (e.g. ${ip}), leading to creation of an invalid URI.

Fixes #12

Required as of Composer 2.2 series

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
…-http

This patch adds a try/catch block within the `LaminasRouter::match()` method around the conversion of the PSR-7 request to a laminas-http request.
It catches laminas-http `InvalidArgumentException`s, and checks for a previous exception matching a laminas-http `InvalidUriPartException`.
When detected, it returns a `RouteResult` indicating a routing failure; otherwise, it rethrows the exception.

The patch is intended to fix scenarios where the Host header is invalid (e.g. `${ip}`), leading to creation of an invalid URI.

Fixes mezzio#12

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Tested locally, and update operations, both with and without `--prefer-lowest`, work without errors now.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
@weierophinney weierophinney added this to the 3.4.0 milestone Jan 6, 2022
@weierophinney weierophinney added the Enhancement New feature or request label Jan 6, 2022
@Ocramius
Copy link
Member

Ocramius commented Jan 6, 2022

@weierophinney perhaps to be released as bugfix?

@weierophinney
Copy link
Contributor Author

@weierophinney perhaps to be released as bugfix?

It's a slight behavior change; previously, you'd get an uncaught exception that would bubble up to the error handler, but now you'll get a route failure. I think it makes sense to call it out in a minor.

@Ocramius Ocramius self-assigned this Jan 6, 2022
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

🚢

@Ocramius Ocramius merged commit 70a3a02 into mezzio:3.4.x Jan 6, 2022
@Ocramius
Copy link
Member

Ocramius commented Jan 6, 2022

Thanks @weierophinney!

@weierophinney weierophinney deleted the feature/catch-uri-errors branch January 6, 2022 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid host in request fails with Internal Server Error
2 participants