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

[docs] Add clarification regarding order of middleware execution #1909

Closed
amitsaha opened this issue May 22, 2017 · 5 comments
Closed

[docs] Add clarification regarding order of middleware execution #1909

amitsaha opened this issue May 22, 2017 · 5 comments
Labels
Milestone

Comments

@amitsaha
Copy link

Long story short

Clarify/Explain the order of execution when multiple middleware factories are registered.

Expected behaviour

Consider the following application:

from aiohttp import web
def test(request):
    print('Handler function called')
    return web.Response(text="Hello")

async def middleware1(app, handler):
    async def middleware_handler(request):
        print('Middleware 1 called')
        response = await handler(request)
        print('Middleware 1 finished')

        return response
    return middleware_handler

async def middleware2(app, handler):
    async def middleware_handler(request):
        print('Middleware 2 called')
        response = await handler(request)
        print('Middleware 2 finished')

        return response
    return middleware_handler


app = web.Application(middlewares=[middleware1, middleware2])
app.router.add_get('/', test)
web.run_app(app)

The above code would produce the following output:

Middleware 1 called
Middleware 2 called
Handler function called
Middleware 2 finished
Middleware 1 finished

I think an explanation like this may improve the current documentation which is brief.

Actual behaviour

IMHO, the current explanation linked above is brief and perhaps is not clear to someone new to aiohttp.

Steps to reproduce

NA

Your environment

NA

@amitsaha
Copy link
Author

Would be happy to work on a PR.

@asvetlov
Copy link
Member

Please do.
I love documentation updates for covering not obvious dark corners.

@amitsaha
Copy link
Author

amitsaha commented Aug 5, 2017

Thanks, sorry I never submitted the PR :-(

@asvetlov
Copy link
Member

asvetlov commented Aug 5, 2017

NP

@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
Projects
None yet
Development

No branches or pull requests

2 participants