diff --git a/docs/api.md b/docs/api.md index 234665fe..0910e4a4 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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. diff --git a/lib/NetworkManager.js b/lib/NetworkManager.js index aba155ea..74974ffa 100644 --- a/lib/NetworkManager.js +++ b/lib/NetworkManager.js @@ -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} */ diff --git a/test/network.spec.js b/test/network.spec.js index 6268dcc3..72773583 100644 --- a/test/network.spec.js +++ b/test/network.spec.js @@ -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));