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

Requests with scope type "websocket" raise a KeyError because there are no method for this kind of asgi request #2

Open
hartym opened this issue Jun 19, 2024 · 0 comments

Comments

@hartym
Copy link

hartym commented Jun 19, 2024

The asgi scope definition for "websocket" requests does not contain a "method" entry (cf https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope). The BaseMiddleware from asgi-tools calls __process__ if scope in ("http", "websocket") (default, overridable at class level).

Thus this causes an exception for all websocket requests:

path, method = scope["path"], scope["method"]

I'm not sure on how this should behave for websocket requests, I fix it for now be removing the "websocket" scope from the middleware scopes but this is a local workaround.

asgi_app = PrometheusMiddleware(asgi_app, metrics_url=_metrics_url, group_paths=["/"])
asgi_app.scopes = ("http",)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant