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

Add empty connexion middleware #1492

Merged
merged 3 commits into from
Mar 24, 2022

Conversation

RobbeSneyders
Copy link
Member

Part of #1489

This PR adds the empty ConnexionMiddleware and wraps it around the FlaskApp using the a2wsgi.WSGIMiddleware adapter.

The ConnexionMiddleware and FlaskApp both implement the ASGI interface, and an ASGI server is the recommended way to run it.

The a2wsgi.ASGIMiddleware adapter is wrapped around the ASGI middleware to make it WSGI compliant so it can be used by the development server and test client.

@@ -31,6 +32,38 @@ def json(self):
return json.loads(self.text)


def fixed_get_environ():
Copy link
Member Author

Choose a reason for hiding this comment

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

The WSGIMiddleware and test client were unfortunately not compatible (see abersheeran/a2wsgi#21, pallets/werkzeug#2347). The issues are fixed, but I still had to patch the test client since the fixes are not released and I don't want to restrict the versions too much.

@@ -44,23 +44,23 @@ def test_errors(problem_app):

get_problem = app_client.get('/v1.0/problem') # type: flask.Response
assert get_problem.content_type == 'application/problem+json'
assert get_problem.status_code == 418
Copy link
Member Author

Choose a reason for hiding this comment

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

a2wsgi.ASGIMiddleware uses the builtin http module underneath, which only supports status code 418 on Python 3.9+.

@RobbeSneyders RobbeSneyders changed the base branch from feature/drop-aiohttp to feature/python3.10 March 18, 2022 13:54
connexion/apps/flask_app.py Outdated Show resolved Hide resolved
@@ -23,16 +23,18 @@ def read_version(package):
'clickclick>=1.2,<21',
'jsonschema>=2.5.1,<5',
'PyYAML>=5.1,<7',
'requests>=2.19.1,<3',
'requests>=2.27,<3',
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to bump to 2.27?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because of a sub-dependency which is shared by both requests and starlette. We'll be able to drop the requests dependency once we move security into the middleware stack though, since we'll only need the AsyncSecurityHandlerFactory then.

connexion/middleware/main.py Outdated Show resolved Hide resolved
"""
if middlewares is None:
middlewares = self.default_middlewares
self.app, self.apps = self._apply_middlewares(app, middlewares)
Copy link
Member

Choose a reason for hiding this comment

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

If I understand correctly, the apps and middlewares will have the opposite direction, given that we iterate on the reversed middlewares?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. Probably not the most logical, so will return them reversed as well.

@RobbeSneyders RobbeSneyders merged commit fe03909 into feature/python3.10 Mar 24, 2022
@RobbeSneyders RobbeSneyders deleted the feature/connexion-middleware branch March 24, 2022 21:51
@RobbeSneyders RobbeSneyders restored the feature/connexion-middleware branch March 24, 2022 21:56
@RobbeSneyders
Copy link
Member Author

Accidentally merged this one due to rebase hell @Ruwann.
Will reopen.

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

Successfully merging this pull request may close these issues.

2 participants