fix(bidi): report correct response sizes on Chrome and Firefox - #42700
Ashraf Ali (ashrafiucse) wants to merge 2 commits into
Conversation
network.ResponseCompleted's |bodySize| and |headersSize| carry different meanings per engine: Chrome's |bodySize| is the full transfer size, including the status line and headers, just like CDP's encodedDataLength, and its |headersSize| omits the status line and the final CRLF. Firefox's |bodySize| is the response body size and its |headersSize| is the full header block size. Map the fields to transferSize/encodedBodySize/ responseHeadersSize per engine so request().sizes() matches the other backends. Fixes: microsoft#42697
|
Reporter of #42697 here. Ran the original reproducer against this branch on both bidi transports, 2000 byte body with So Chrome now agrees with CDP on both fields and Firefox is not regressed, which was the risk with the naive subtraction I had suggested on the issue. Thanks for digging into the raw |
|
Thanks for running it against both engines — that's exactly the check I was hoping someone would do, and matching CDP on both fields is the outcome we wanted here. Honestly, your report made this fix a lot easier than it could've been. The two suspect lines and the And genuinely — keep filing reports like this one. A repro that runs first try, plus a cause narrowed down to two lines, is better than a lot of what lands in most trackers, freshman or not. |
| // Chrome's |bodySize| is the transfer size (status line + headers + body), | ||
| // derive the encoded body size by subtracting the full header block size. | ||
| response.setTransferSize(bodySize); | ||
| response.setEncodedBodySize(bodySize - headersSize - this._headerBlockOverheadSize(params.response)); |
There was a problem hiding this comment.
this works around an upstream bodySize bug but produces negative sizes for HTTP/2 and cache hits
| } else { | ||
| // Firefox's |bodySize| is the encoded body size, and its |headersSize| | ||
| // already includes the status line and the final CRLF. | ||
| response.setTransferSize(headersSize + bodySize); |
There was a problem hiding this comment.
this sum omits chunked framing and counts cached bodies as transferred bytes
i think bytesReceived already contains the correct value
Transfer size now comes from |bytesReceived| on both engines: it is the number of bytes actually read off the network, including the header block and the chunked framing, and is 0 for cached responses. This also fixes two issues with the previous change-requested approach found in review: - Chrome's header block subtraction produced negative body sizes for cached responses (|bodySize| of 0) and for HTTP/2, where |headersSize| counts the decompressed header lines while |bodySize| is a wire size. The subtraction is now limited to fresh HTTP/1.x responses; everything else falls back to the content-length based computation in network.ts. - Firefox's |headersSize| + |bodySize| sum counted cached bodies as transferred bytes and omitted the chunked framing.
|
Thanks for the review — you were right on both counts, and
Spot-checked against CDP after the change: fixed/gzip report identical |
|
FYI im working on fixing part of this upstream https://chromium-review.googlesource.com/c/chromium/src/+/8411449 |
Summary
network.ResponseCompleted'sbodySize/headersSizecarry different meanings per engine: Chrome'sbodySizeis the full transfer size (status line + headers + body, like CDP'sencodedDataLength) and itsheadersSizeomits the status line and the final CRLF; Firefox'sbodySizeis the body size and itsheadersSizeis the full header block. The old code fed one field into both metrics, sorequest().sizes()over-reportedresponseBodySizeby the header size on Chrome.bidiNetworkManagerand align Chrome'sresponseHeadersSizewith the other backends. The overhead computation matches theresponseHeadersSize()fallback innetwork.ts, sotransferSize = responseHeadersSize + encodedBodySizeholds on both engines (including for HTTP/2, consistent with the existing fallback).page-network-sizesentries removed from thebidi-chromium-pageexpectations.Fixes #42697