tirkarthi opened a new issue, #60165:
URL: https://github.com/apache/airflow/issues/60165

   ### Apache Airflow version
   
   3.1.5
   
   ### If "Other Airflow 3 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   We have a service that takes requests of certain url paths of Airflow API 
and then uses http client to hit Airflow API service and returns the response 
with headers back to the load balancer nginx. After upgrade from Airflow 3.1.2 
to 3.1.5 we noticed the service is able to hit the Airflow API but there is a 
change in the header and the response type where in Airflow 3.1.2 it was not 
chunked and in Airflow 3.1.5 it was chunked. The chunked header is returned 
back to nginx which also tries to add it's own header which results in error 
'upstream sent duplicate header line: "Transfer-Encoding: chunked"' . This 
results in nginx sending 504 response.
   
   Upon debugging it seems that JWTRefreshMiddleware was added in #55506 with 
that the middleware order becomes JWTRefreshMiddleware -> GZipMiddleware. The 
requests go through middleware from top to bottom and the responses go through 
bottom to top. Looks like JWTRefreshMiddleware is added before GZipMiddleware 
resulting in chunked vs non-chunked response behavior change.` Upon adjusting 
the order in `airflow-core/src/airflow/api_fastapi/core_api/app.py` we were 
able to restore the previous behavior. As per my understanding `GZipMiddleware` 
should process response to compress it after `JWTRefreshMiddleware` in terms of 
the response cycle. There was no change in frontend and other parts but we 
thought to file an issue anyway.
   
   
   ```python
   app.add_middleware(GZipMiddleware, minimum_size=100, compresslevel=5)
   app.add_middleware(JWTRefreshMiddleware)
   ```
   
   ```python
   import httpx
   dict(httpx.get("http://localhost:8000/api/v2/monitor/health";).headers)
   {'date': 'Tue, 06 Jan 2026 13:46:29 GMT', 'server': 'uvicorn', 
'content-length': '170', 
   'content-type': 'application/json', 'content-encoding': 'gzip', 'vary': 
'Accept-Encoding'}
   ```
   
   Change order to have GZipMiddleware at last.
   
   ```python
   app.add_middleware(JWTRefreshMiddleware)
   app.add_middleware(GZipMiddleware, minimum_size=100, compresslevel=5)
   ```
   
   ```python
   import httpx
   dict(httpx.get("http://localhost:8000/api/v2/monitor/health";).headers)
   {'date': 'Tue, 06 Jan 2026 14:31:51 GMT', 'server': 'uvicorn', 
'content-type': 'application/json', 
   'content-encoding': 'gzip', 'vary': 'Accept-Encoding', 'transfer-encoding': 
'chunked'}
   ```
   
   ### What you think should happen instead?
   
   _No response_
   
   ### How to reproduce
   
   Change order and compress size as above in 
`airflow-core/src/airflow/api_fastapi/core_api/app.py` and use httpx to analyse 
the change in headers.
   
   ### Operating System
   
   Ubuntu 20.04
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Virtualenv installation
   
   ### Deployment details
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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]

Reply via email to