Skip to content

Commit

Permalink
fix: parse statusText from the extraInfo event (#7798)
Browse files Browse the repository at this point in the history
Issues: #7458
  • Loading branch information
OrKoN committed Nov 26, 2021
1 parent ac162c5 commit a26b12b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/common/HTTPResponse.ts
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down
11 changes: 11 additions & 0 deletions test/network.spec.ts
Expand Up @@ -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 () {
Expand Down

0 comments on commit a26b12b

Please sign in to comment.