fix: parse statusText from the extraInfo event (#7798)

Issues: #7458
This commit is contained in:
Alex Rudenko 2021-11-26 09:17:34 +01:00 committed by GitHub
parent ac162c561e
commit a26b12b7c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -78,8 +78,9 @@ export class HTTPResponse {
ip: responsePayload.remoteIPAddress,
port: responsePayload.remotePort,
};
// TODO extract statusText from extraInfo.headersText instead if present
this._statusText = responsePayload.statusText;
this._statusText =
this._parseStatusTextFromExtrInfo(extraInfo) ||
responsePayload.statusText;
this._url = request.url();
this._fromDiskCache = !!responsePayload.fromDiskCache;
this._fromServiceWorker = !!responsePayload.fromServiceWorker;
@ -94,6 +95,22 @@ export class HTTPResponse {
: null;
}
/**
* @internal
*/
_parseStatusTextFromExtrInfo(
extraInfo: Protocol.Network.ResponseReceivedExtraInfoEvent | null
): string | undefined {
if (!extraInfo || !extraInfo.headersText) return;
const firstLine = extraInfo.headersText.split('\r', 1)[0];
if (!firstLine) return;
const match = firstLine.match(/[^ ]* [^ ]* (.*)/);
if (!match) return;
const statusText = match[1];
if (!statusText) return;
return statusText;
}
/**
* @internal
*/

View File

@ -417,6 +417,17 @@ describe('network', function () {
const response = await page.goto(server.PREFIX + '/cool');
expect(response.statusText()).toBe('cool!');
});
it('handles missing status text', async () => {
const { page, server } = getTestState();
server.setRoute('/nostatus', (req, res) => {
res.writeHead(200, '');
res.end();
});
const response = await page.goto(server.PREFIX + '/nostatus');
expect(response.statusText()).toBe('');
});
});
describeFailsFirefox('Network Events', function () {