mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
parent
ac162c561e
commit
a26b12b7c7
@ -78,8 +78,9 @@ export class HTTPResponse {
|
|||||||
ip: responsePayload.remoteIPAddress,
|
ip: responsePayload.remoteIPAddress,
|
||||||
port: responsePayload.remotePort,
|
port: responsePayload.remotePort,
|
||||||
};
|
};
|
||||||
// TODO extract statusText from extraInfo.headersText instead if present
|
this._statusText =
|
||||||
this._statusText = responsePayload.statusText;
|
this._parseStatusTextFromExtrInfo(extraInfo) ||
|
||||||
|
responsePayload.statusText;
|
||||||
this._url = request.url();
|
this._url = request.url();
|
||||||
this._fromDiskCache = !!responsePayload.fromDiskCache;
|
this._fromDiskCache = !!responsePayload.fromDiskCache;
|
||||||
this._fromServiceWorker = !!responsePayload.fromServiceWorker;
|
this._fromServiceWorker = !!responsePayload.fromServiceWorker;
|
||||||
@ -94,6 +95,22 @@ export class HTTPResponse {
|
|||||||
: null;
|
: 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
|
* @internal
|
||||||
*/
|
*/
|
||||||
|
@ -417,6 +417,17 @@ describe('network', function () {
|
|||||||
const response = await page.goto(server.PREFIX + '/cool');
|
const response = await page.goto(server.PREFIX + '/cool');
|
||||||
expect(response.statusText()).toBe('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 () {
|
describeFailsFirefox('Network Events', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user