This is an automated email from the ASF dual-hosted git repository. jedcunningham pushed a commit to branch v2-4-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 1723b86a8dd1a9a5c903abb369bb5b548033723e Author: sprohaska <[email protected]> AuthorDate: Thu Sep 22 09:02:36 2022 +0200 fix WSGI root app (#26549) * fix WSGI root app The `start_response()` callable expects a string in argument `status`. See <https://peps.python.org/pep-0333/#the-start-response-callable>. Signed-off-by: Steffen Prohaska <[email protected]> * Better type WSGI middleware This provides typing guardrails for the middleware callable. Signed-off-by: Steffen Prohaska <[email protected]> Co-authored-by: Tzu-ping Chung <[email protected]> (cherry picked from commit 39f99ec612ed3a56b033c7a21c93000b7e1a59b5) --- airflow/www/extensions/init_wsgi_middlewares.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/airflow/www/extensions/init_wsgi_middlewares.py b/airflow/www/extensions/init_wsgi_middlewares.py index 0943d5dfd5..f146fb9b6b 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 werkzeug.middleware.proxy_fix import ProxyFix from airflow.configuration import conf +if TYPE_CHECKING: + from _typeshed.wsgi import StartResponse, WSGIEnvironment + -def _root_app(_, resp): - resp(b'404 Not Found', [('Content-Type', 'text/plain')]) +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'):
