Skip to content

Commit

Permalink
feat(network): introduce Response.statusText() (#3193)
Browse files Browse the repository at this point in the history
Fixes #317.
  • Loading branch information
aslushnikov committed Sep 5, 2018
1 parent 84c2621 commit 7f9e276
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/api.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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.

Expand Down
8 changes: 8 additions & 0 deletions lib/NetworkManager.js
Expand Up @@ -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;
Expand Down Expand Up @@ -544,6 +545,13 @@ class Response {
return this._status;
}

/**
* @return {string}
*/
statusText() {
return this._statusText;
}

/**
* @return {!Object}
*/
Expand Down
9 changes: 9 additions & 0 deletions test/network.spec.js
Expand Up @@ -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));
Expand Down

0 comments on commit 7f9e276

Please sign in to comment.