feat: add on_response_headers_received signal to TraceConfig#12535
feat: add on_response_headers_received signal to TraceConfig#12535ykd007 wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12535 +/- ##
=======================================
Coverage 98.94% 98.94%
=======================================
Files 131 131
Lines 46622 46638 +16
Branches 2414 2416 +2
=======================================
+ Hits 46132 46148 +16
Misses 367 367
Partials 123 123
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Merging this PR will not alter performance
Comparing Footnotes
|
| if self._traces: | ||
| for trace in self._traces: | ||
| await trace.send_response_headers_received( | ||
| self.method, self.url, cast(CIMultiDictProxy[str], self._headers) |
|
|
||
| method: str | ||
| url: URL | ||
| headers: "CIMultiDictProxy[str]" |
There was a problem hiding this comment.
It looks like our other ones currently use CIMultiDict. Considering that tracing is going to be in performance-critical paths, I think it should just use whatever the code uses. Judging by your cast(), I'd assume it's actually CIMultiDict like the others.
There was a problem hiding this comment.
Alternatively, and probably longer term, we could consider adding a MultiMapping type to multidict that would be compatible with both classes and provide immutability at the typing level.
Closes #7386
Summary
Adds the missing
on_response_headers_receivedsignal toTraceConfig, allowing users to observe response headers as soon as they are parsed from the server — before the response body is consumed.Changes
aiohttp/tracing.py— AddedTraceResponseHeadersReceivedParamsdataclass (method,url,headers: CIMultiDictProxy[str]),on_response_headers_receivedsignal toTraceConfig, andTrace.send_response_headers_received()methodaiohttp/client_reqrep.py— Fire the signal inClientResponse.start()after headers are parsed, before payload is settests/test_tracing.py— AddedTraceResponseHeadersReceivedParamsto freeze test + parametrizedtest_sendcoverageCHANGES/7386.feature.rst— Towncrier changelog fragmentSignal firing point
Fires in
ClientResponse.start()immediately afterself._headers = message.headersis set, beforeself.content = payload. Subscribers receive the full parsed response headers (and status line) but no body bytes yet — symmetric to howon_request_headers_sentfires after request headers are written but before the body.