Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 164b82e

Browse files
author
Thiago Perrotta
committedJun 28, 2023
network: populate response headers size
Note: In the absence of WPT tests that verify this field, it may be slightly off by a few bytes. Bug: #765
1 parent f7271ff commit 164b82e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed
 

‎src/bidiMapper/domains/network/networkRequest.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ export class NetworkRequest {
292292
this.#responseReceivedExtraInfoEvent = undefined;
293293
}
294294

295+
const headers = NetworkRequest.#getHeaders(
296+
this.#responseReceivedEvent.response.headers
297+
);
298+
295299
return {
296300
method: Network.EventNames.ResponseCompletedEvent,
297301
params: {
@@ -307,13 +311,10 @@ export class NetworkRequest {
307311
this.#responseReceivedEvent.response.fromDiskCache ||
308312
this.#responseReceivedEvent.response.fromPrefetchCache ||
309313
this.#servedFromCache,
310-
headers: NetworkRequest.#getHeaders(
311-
this.#responseReceivedEvent.response.headers
312-
),
314+
headers,
313315
mimeType: this.#responseReceivedEvent.response.mimeType,
314316
bytesReceived: this.#responseReceivedEvent.response.encodedDataLength,
315-
headersSize:
316-
this.#responseReceivedExtraInfoEvent?.headersText?.length ?? 0,
317+
headersSize: this.#computeResponseHeadersSize(headers),
317318
// TODO: consider removing from spec.
318319
bodySize: 0,
319320
content: {
@@ -325,6 +326,12 @@ export class NetworkRequest {
325326
};
326327
}
327328

329+
#computeResponseHeadersSize(headers: Network.Header[]): number {
330+
return headers.reduce((total, header) => {
331+
return total + header.name.length + (header.value?.length ?? 0) + 4; // 4 = ': ' + '\r\n'
332+
}, 0);
333+
}
334+
328335
#isIgnoredEvent(): boolean {
329336
return (
330337
this.#requestWillBeSentEvent?.request.url.endsWith('/favicon.ico') ??

0 commit comments

Comments
 (0)
Please sign in to comment.