Azure / azure-functions-python-library

Azure Functions Python SDK
MIT License
150 stars 63 forks source link

Support ASGI middleware chains by only yielding http.disconnect when response has been fully received #153

Closed tonybaloney closed 1 year ago

tonybaloney commented 1 year ago

Fixes a bug where http.disconnect would be sent even though the ASGI middleware hadn't received the whole response, which yielded empty responses.

This was shown with 2 or more pieces of FastAPI middleware because it would send them in chunks.

As per the ASGI spec, http.disconnect should be sent when:

Sent to the application if receive is called after a response has been sent or after the HTTP connection has been closed. This is mainly useful for long-polling, where you may want to trigger cleanup code if the connection closes early.

So the receive method has been changed to only send then when all response body has been added to the buffer.

Fixes https://github.com/Azure/azure-functions-python-worker/issues/1104

codecov[bot] commented 1 year ago

Codecov Report

Merging #153 (1f0926e) into dev (bd11d48) will decrease coverage by 0.05%. The diff coverage is 71.42%.

@@            Coverage Diff             @@
##              dev     #153      +/-   ##
==========================================
- Coverage   90.13%   90.08%   -0.06%     
==========================================
  Files          50       50              
  Lines        3002     3005       +3     
  Branches      400      401       +1     
==========================================
+ Hits         2706     2707       +1     
- Misses        220      221       +1     
- Partials       76       77       +1     
Flag Coverage Δ
unittests 90.04% <71.42%> (-0.06%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
azure/functions/_http_asgi.py 90.42% <71.42%> (-1.89%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.