feat(network): introduce Response.statusText() (#3193)

Fixes #317.
This commit is contained in:
Andrey Lushnikov 2018-09-05 21:03:24 +01:00 committed by GitHub
parent 84c2621dd4
commit 7f9e276733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -269,6 +269,7 @@
* [response.request()](#responserequest)
* [response.securityDetails()](#responsesecuritydetails)
* [response.status()](#responsestatus)
* [response.statusText()](#responsestatustext)
* [response.text()](#responsetext)
* [response.url()](#responseurl)
- [class: SecurityDetails](#class-securitydetails)
@ -3089,6 +3090,11 @@ Contains a boolean stating whether the response was successful (status in the ra
Contains the status code of the response (e.g., 200 for a success).
#### response.statusText()
- returns: <[string]>
Contains the status text of the response (e.g. usually an "OK" for a success).
#### response.text()
- returns: <[Promise]<[string]>> Promise which resolves to a text representation of response body.

View File

@ -507,6 +507,7 @@ class Response {
port: responsePayload.remotePort,
};
this._status = responsePayload.status;
this._statusText = responsePayload.statusText;
this._url = request.url();
this._fromDiskCache = !!responsePayload.fromDiskCache;
this._fromServiceWorker = !!responsePayload.fromServiceWorker;
@ -544,6 +545,13 @@ class Response {
return this._status;
}
/**
* @return {string}
*/
statusText() {
return this._statusText;
}
/**
* @return {!Object}
*/

View File

@ -62,6 +62,15 @@ module.exports.addTests = function({testRunner, expect}) {
expect(remoteAddress.port).toBe(server.PORT);
});
it('Response.statusText', async({page, server}) => {
server.setRoute('/cool', (req, res) => {
res.writeHead(200, 'cool!');
res.end();
});
const response = await page.goto(server.PREFIX + '/cool');
expect(response.statusText()).toBe('cool!');
});
it('Response.fromCache()', async({page, server}) => {
const responses = new Map();
page.on('response', r => responses.set(r.url().split('/').pop(), r));