From 8597a77ff244c50824aeaf8467f60f0aac7a7d21 Mon Sep 17 00:00:00 2001 From: Steffen Prohaska Date: Wed, 21 Sep 2022 11:49:47 +0200 Subject: [PATCH 1/2] fix WSGI root app The `start_response()` callable expects a string in argument `status`. See . Signed-off-by: Steffen Prohaska --- airflow/www/extensions/init_wsgi_middlewares.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow/www/extensions/init_wsgi_middlewares.py b/airflow/www/extensions/init_wsgi_middlewares.py index 0943d5dfd56bf..f654cff507b10 100644 --- a/airflow/www/extensions/init_wsgi_middlewares.py +++ b/airflow/www/extensions/init_wsgi_middlewares.py @@ -26,7 +26,7 @@ def _root_app(_, resp): - resp(b'404 Not Found', [('Content-Type', 'text/plain')]) + resp('404 Not Found', [('Content-Type', 'text/plain')]) return [b'Apache Airflow is not at this location'] From c268886233f0d57afc24cff341b3f77c07e902c4 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 22 Sep 2022 10:30:56 +0800 Subject: [PATCH 2/2] Better type WSGI middleware This provides typing guardrails for the middleware callable. --- airflow/www/extensions/init_wsgi_middlewares.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/airflow/www/extensions/init_wsgi_middlewares.py b/airflow/www/extensions/init_wsgi_middlewares.py index f654cff507b10..f146fb9b6beab 100644 --- a/airflow/www/extensions/init_wsgi_middlewares.py +++ b/airflow/www/extensions/init_wsgi_middlewares.py @@ -14,8 +14,10 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + from __future__ import annotations +from typing import TYPE_CHECKING, Iterable from urllib.parse import urlparse from flask import Flask @@ -24,22 +26,24 @@ from airflow.configuration import conf +if TYPE_CHECKING: + from _typeshed.wsgi import StartResponse, WSGIEnvironment + -def _root_app(_, resp): +def _root_app(env: WSGIEnvironment, resp: StartResponse) -> Iterable[bytes]: resp('404 Not Found', [('Content-Type', 'text/plain')]) return [b'Apache Airflow is not at this location'] -def init_wsgi_middleware(flask_app: Flask): +def init_wsgi_middleware(flask_app: Flask) -> None: """Handle X-Forwarded-* headers and base_url support""" # Apply DispatcherMiddleware base_url = urlparse(conf.get('webserver', 'base_url'))[2] if not base_url or base_url == '/': base_url = "" if base_url: - flask_app.wsgi_app = DispatcherMiddleware( # type: ignore - _root_app, mounts={base_url: flask_app.wsgi_app} # type: ignore - ) + wsgi_app = DispatcherMiddleware(_root_app, mounts={base_url: flask_app.wsgi_app}) + flask_app.wsgi_app = wsgi_app # type: ignore[assignment] # Apply ProxyFix middleware if conf.getboolean('webserver', 'ENABLE_PROXY_FIX'):