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

add_static breaks normalize_path_middleware #3086

Closed
GeorgeTG opened this issue Jun 18, 2018 · 2 comments
Closed

add_static breaks normalize_path_middleware #3086

GeorgeTG opened this issue Jun 18, 2018 · 2 comments
Labels
invalid This doesn't seem right outdated

Comments

@GeorgeTG
Copy link

Long story short

If the root router has an add_static on '/', normalize_path_middleware won't work.

Expected behaviour

A slash to be appended at the end of the url

Actual behaviour

Route /example returns 404 when /example/ is registered.
in normalize_path_middleware at the definition of impl coroutine theres this check:
if isinstance(request.match_info.route, SystemRoute):
Normally request.match_info.route is a <SystemRoute: 404>
With add_static it becomes <class 'aiohttp.web_urldispatcher.ResourceRoute'>
So the middleware ignores it.

Steps to reproduce

Setup routes like so:

def setup_routes(app):
    app.router.add_get('/example/', example_route, name="example")
    app.router.add_static('/', my_path)

And of course enable normalize_path_middleware
Try to get /examples

Your environment

aiohttp 3.0.4 - Server
python 3.6
archlinux @ latest

@asvetlov asvetlov added the invalid This doesn't seem right label Jun 18, 2018
@asvetlov
Copy link
Member

The problem is in your code, not in add_static or normalize_path_middleware.
The middleware is applied if path is not resolved without slash normalization.
Registering a wildcard static route for root path consmes all possible paths.
Thus, middleware is never processed: all possible paths are going to the static handler.

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right outdated
Projects
None yet
Development

No branches or pull requests

2 participants