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

Middleware #51

Closed
tomchristie opened this issue Oct 15, 2018 · 6 comments
Closed

Middleware #51

tomchristie opened this issue Oct 15, 2018 · 6 comments
Labels
feature New feature or request

Comments

@tomchristie
Copy link
Contributor

tomchristie commented Oct 15, 2018

Supporting ASGI middleware would be a really good way to compartmentalise away bits of complexity, as we all promoting more of a cross-framework ecosystem.

I'd suggest an interface of app.add_middleware(cls, **options)

We could then do things like:

  • Move the GZip handling out of Response, and use Starlette's GzipMiddleware, which will also take care of handling streaming responses (once responder has those)
  • Be able to use Starlette's CORSMiddleware.

We can set up a default set of middleware if needed based on the configuration options presented to the API(...) class.

Any objections or considerations?

@kennethreitz kennethreitz added the feature New feature or request label Oct 16, 2018
@kennethreitz
Copy link
Owner

kennethreitz commented Oct 16, 2018

I'm open to that:

    def add_middleware(self, middleware_class, **options):
        self.middleware.append(middleware_class(self, **options))

@tomchristie
Copy link
Contributor Author

Also useful here - Starlette's ExceptionMiddleware

@ajitid
Copy link

ajitid commented Oct 16, 2018

Hey, any idea how to turn on debug mode in Responder?

@kennethreitz
Copy link
Owner

@ajitid it doesn't have it yet :)

@tomchristie
Copy link
Contributor Author

tomchristie commented Oct 16, 2018

Run it using uvicorn --debug example:app and you'll get in-browser tracebacks on exceptions and auto-reloading.

uvicorn.run(..., debug=True) is the equivalent thing programmatically, and will give you in-browser tracebacks, but isn't able to do auto-reloads.

@ajitid
Copy link

ajitid commented Oct 16, 2018

The reloader is not enabled when running programmatically.

Didn't knew this, and got confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants