Skip to content

Normalize path middleware#362

Closed
asvetlov wants to merge 5 commits intomasterfrom
normalize_path_middleware
Closed

Normalize path middleware#362
asvetlov wants to merge 5 commits intomasterfrom
normalize_path_middleware

Conversation

@asvetlov
Copy link
Member

Implement normalize_path_middleware (see #355)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm... catching HTTPNotFound here may lead to unexpected behavior, imagine the following use case:

app.router.add_route("GET", "/root/resource", handler1)
app.router.add_route("GET", "/root/resource/{tail:.*}", handler2)

def handler1(req):
    if not has_permission(req):
        raise web.HTTPNotFound()   # we don't want to expose this resource
    # ....

def handler2(req):
    pass

In this case application will expose /root/resource/ url (that it is exsist) and also it may be hard to debug such cases.

Copy link
Member

Choose a reason for hiding this comment

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

Checking that request.match_info is instance of _NotFoundMatchInfo might resolve this issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

sloria added a commit to sloria/aiohttp-utils that referenced this pull request Oct 25, 2015
I realized half-way through implementing this that this is
already being implemented in aio-libs/aiohttp#362, so right
now this is mostly a copy-n-paste of that code.
Keeping this for now because it is still useful to have the
setup function for reading app config.

Once that PR is merged, much of this code can go away.
@sloria
Copy link
Contributor

sloria commented Oct 25, 2015

Just wondering: what is the status of this? I was working on similar middleware before I found this PR. I ended up copying much of this implementation into a utility library, aiohttp_utils. If/when this is merged, I can remove much of that code from aiohttp_utils. I can maintain the code there until then.

@asvetlov
Copy link
Member Author

I've switched to another issues and totally forgot about this one.
The main reason for postponing was adding resolve2 method -- I had a feel the resolving mechanic is not flexible enough but doubted about the best solution.
If you want to resurrect the problem let's discuss.

@sloria
Copy link
Contributor

sloria commented Oct 26, 2015

I don't think this needs to be a priority. The implementation I have in aiohttp_utils works fine for my purposes.

@asvetlov asvetlov closed this Jul 26, 2016
@asvetlov asvetlov deleted the normalize_path_middleware branch July 26, 2016 09:22
@lock
Copy link

lock bot commented Oct 29, 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.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants