mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(firefox) support Request.headers() & Response.headers() (#3993)
This commit is contained in:
parent
89d0f1e1e7
commit
31ae1d6d15
@ -103,6 +103,13 @@ class Request {
|
|||||||
this._isNavigationRequest = payload.isNavigationRequest;
|
this._isNavigationRequest = payload.isNavigationRequest;
|
||||||
this._method = payload.method;
|
this._method = payload.method;
|
||||||
this._resourceType = causeToResourceType[payload.cause] || 'other';
|
this._resourceType = causeToResourceType[payload.cause] || 'other';
|
||||||
|
this._headers = {};
|
||||||
|
for (const {name, value} of payload.headers)
|
||||||
|
this._headers[name.toLowerCase()] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
headers() {
|
||||||
|
return {...this._headers};
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectChain() {
|
redirectChain() {
|
||||||
@ -141,6 +148,13 @@ class Response {
|
|||||||
this._remotePort = payload.remotePort;
|
this._remotePort = payload.remotePort;
|
||||||
this._status = payload.status;
|
this._status = payload.status;
|
||||||
this._statusText = payload.statusText;
|
this._statusText = payload.statusText;
|
||||||
|
this._headers = {};
|
||||||
|
for (const {name, value} of payload.headers)
|
||||||
|
this._headers[name.toLowerCase()] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
headers() {
|
||||||
|
return {...this._headers};
|
||||||
}
|
}
|
||||||
|
|
||||||
status() {
|
status() {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"node": ">=8.9.4"
|
"node": ">=8.9.4"
|
||||||
},
|
},
|
||||||
"puppeteer": {
|
"puppeteer": {
|
||||||
"firefox_revision": "309b4f8466e83360f2045be982d2c61522bcf466"
|
"firefox_revision": "167f4a537c7d87e967f5c1ce71fc9a100c347c8b"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "node install.js",
|
"install": "node install.js",
|
||||||
|
@ -18,7 +18,7 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
module.exports.addTests = function({testRunner, expect}) {
|
module.exports.addTests = function({testRunner, expect, CHROME}) {
|
||||||
const {describe, xdescribe, fdescribe, describe_fails_ffox} = testRunner;
|
const {describe, xdescribe, fdescribe, describe_fails_ffox} = testRunner;
|
||||||
const {it, fit, xit, it_fails_ffox} = testRunner;
|
const {it, fit, xit, it_fails_ffox} = testRunner;
|
||||||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||||
@ -73,6 +73,27 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Request.headers', function() {
|
||||||
|
it('should work', async({page, server}) => {
|
||||||
|
const response = await page.goto(server.EMPTY_PAGE);
|
||||||
|
if (CHROME)
|
||||||
|
expect(response.request().headers()['user-agent']).toContain('Chrome');
|
||||||
|
else
|
||||||
|
expect(response.request().headers()['user-agent']).toContain('Firefox');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Response.headers', function() {
|
||||||
|
it('should work', async({page, server}) => {
|
||||||
|
server.setRoute('/empty.html', (req, res) => {
|
||||||
|
res.setHeader('foo', 'bar');
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
const response = await page.goto(server.EMPTY_PAGE);
|
||||||
|
expect(response.headers()['foo']).toBe('bar');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe_fails_ffox('Response.fromCache', function() {
|
describe_fails_ffox('Response.fromCache', function() {
|
||||||
it('should return |false| for non-cached content', async({page, server}) => {
|
it('should return |false| for non-cached content', async({page, server}) => {
|
||||||
const response = await page.goto(server.EMPTY_PAGE);
|
const response = await page.goto(server.EMPTY_PAGE);
|
||||||
|
Loading…
Reference in New Issue
Block a user