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

fix WSGI root app #26549

Merged
merged 2 commits into from
Sep 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions airflow/www/extensions/init_wsgi_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,22 +26,24 @@

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'):
Expand Down