diff --git a/connexion/apps/flask.py b/connexion/apps/flask.py index f6efe892b..352b9a4b2 100644 --- a/connexion/apps/flask.py +++ b/connexion/apps/flask.py @@ -7,6 +7,7 @@ import flask import werkzeug.exceptions +from a2wsgi import WSGIMiddleware from flask import Response as FlaskResponse from flask import signals from starlette.types import Receive, Scope, Send @@ -17,7 +18,6 @@ from connexion.frameworks import flask as flask_utils from connexion.jsonifier import Jsonifier from connexion.middleware.abstract import AbstractRoutingAPI, SpecMiddleware -from connexion.middleware.wsgi import WSGIMiddleware from connexion.operations import AbstractOperation from connexion.problem import problem from connexion.resolver import Resolver diff --git a/connexion/middleware/wsgi.py b/connexion/middleware/wsgi.py deleted file mode 100644 index 2b98a306f..000000000 --- a/connexion/middleware/wsgi.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -Module that monkey patches a2wsgi to make contextvars available to the WSGI application. -This can be removed once https://github.com/abersheeran/a2wsgi/pull/31 is merged. -""" -import contextvars -import functools - -import a2wsgi.wsgi -from a2wsgi.wsgi import WSGIResponder - - -class ContextWSGIResponder(WSGIResponder): - """Custom Responder that makes contextvars available to the WSGI application.""" - - @property - def wsgi(self): - context = contextvars.copy_context() - return functools.partial(context.run, super().wsgi) - - -# Monkeypatch module with our custom Responder -a2wsgi.wsgi.WSGIResponder = ContextWSGIResponder - -# Import the WSGIMiddleware now so it uses our custom Responder -from a2wsgi import WSGIMiddleware # NOQA diff --git a/pyproject.toml b/pyproject.toml index 7975f706f..b50466f50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ starlette = "^0.25" typing-extensions = "^4" werkzeug = "^2.2.1" -a2wsgi = { version = "^1.4", optional = true } +a2wsgi = { version = "^1.7", optional = true } flask = { version = "^2.2", extras = ["async"], optional = true } py-swagger-ui = { version = "^1.1.0", optional = true } uvicorn = { version = "^0.17.6", extras = ["standard"], optional = true }