Skip to content

Commit a26b12b

Browse files
authored
fix: parse statusText from the extraInfo event (#7798)
Issues: #7458
1 parent ac162c5 commit a26b12b

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/common/HTTPResponse.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ export class HTTPResponse {
7878
ip: responsePayload.remoteIPAddress,
7979
port: responsePayload.remotePort,
8080
};
81-
// TODO extract statusText from extraInfo.headersText instead if present
82-
this._statusText = responsePayload.statusText;
81+
this._statusText =
82+
this._parseStatusTextFromExtrInfo(extraInfo) ||
83+
responsePayload.statusText;
8384
this._url = request.url();
8485
this._fromDiskCache = !!responsePayload.fromDiskCache;
8586
this._fromServiceWorker = !!responsePayload.fromServiceWorker;
@@ -94,6 +95,22 @@ export class HTTPResponse {
9495
: null;
9596
}
9697

98+
/**
99+
* @internal
100+
*/
101+
_parseStatusTextFromExtrInfo(
102+
extraInfo: Protocol.Network.ResponseReceivedExtraInfoEvent | null
103+
): string | undefined {
104+
if (!extraInfo || !extraInfo.headersText) return;
105+
const firstLine = extraInfo.headersText.split('\r', 1)[0];
106+
if (!firstLine) return;
107+
const match = firstLine.match(/[^ ]* [^ ]* (.*)/);
108+
if (!match) return;
109+
const statusText = match[1];
110+
if (!statusText) return;
111+
return statusText;
112+
}
113+
97114
/**
98115
* @internal
99116
*/

test/network.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,17 @@ describe('network', function () {
417417
const response = await page.goto(server.PREFIX + '/cool');
418418
expect(response.statusText()).toBe('cool!');
419419
});
420+
421+
it('handles missing status text', async () => {
422+
const { page, server } = getTestState();
423+
424+
server.setRoute('/nostatus', (req, res) => {
425+
res.writeHead(200, '');
426+
res.end();
427+
});
428+
const response = await page.goto(server.PREFIX + '/nostatus');
429+
expect(response.statusText()).toBe('');
430+
});
420431
});
421432

422433
describeFailsFirefox('Network Events', function () {

0 commit comments

Comments
 (0)