Copilot commented on code in PR #64726:
URL: https://github.com/apache/airflow/pull/64726#discussion_r3066472608
##########
providers/fab/src/airflow/providers/fab/www/app.py:
##########
@@ -59,6 +59,16 @@ def create_app(enable_plugins: bool):
from airflow.providers.fab.auth_manager.fab_auth_manager import
FabAuthManager
flask_app = Flask(__name__)
+
+ @flask_app.after_request
+ def remove_duplicate_date_header(response):
+ date_headers = response.headers.getlist("Date")
+
+ if len(date_headers) > 1:
+ # Keep only the first one (typically from Uvicorn)
+ response.headers.set("Date", date_headers[0])
Review Comment:
`response.headers` here reflects headers produced by the Flask/Werkzeug
response, not headers that Uvicorn adds later at the server layer. In the
common failure mode described (Uvicorn adds `Date` + Flask adds `Date`),
`getlist('Date')` will typically be `['<flask date>']` (len = 1), so this hook
won’t run and duplicates will still happen. Also, keeping a `Date` header in
the app response still results in two headers once Uvicorn adds its own. To
prevent duplication with Uvicorn, remove the `Date` header from the Flask
response unconditionally (or disable Werkzeug’s automatic date header, e.g.,
via the response class), so only the server-provided `Date` is emitted.
```suggestion
# Remove the application-level Date header so the ASGI/WSGI server
# can emit a single Date header for the final response.
response.headers.pop("Date", None)
```
##########
providers/fab/src/airflow/providers/fab/www/app.py:
##########
@@ -59,6 +59,16 @@ def create_app(enable_plugins: bool):
from airflow.providers.fab.auth_manager.fab_auth_manager import
FabAuthManager
flask_app = Flask(__name__)
+
+ @flask_app.after_request
+ def remove_duplicate_date_header(response):
+ date_headers = response.headers.getlist("Date")
+
+ if len(date_headers) > 1:
+ # Keep only the first one (typically from Uvicorn)
Review Comment:
This comment is misleading: Uvicorn’s `Date` header is not generally visible
inside the Flask response object, so the “first one” will typically be
Flask/Werkzeug’s value, not Uvicorn’s. If you keep this approach, update the
comment to match what the code can actually observe (or remove it if switching
to unconditionally removing the `Date` header from the app response).
```suggestion
# Keep only the first Date header present on the Flask response
object.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]