feat(firefox): support page.setExtraHTTPHeaders (#4035)

This commit is contained in:
Andrey Lushnikov 2019-02-19 15:22:12 -08:00 committed by GitHub
parent c118b208fa
commit 719ee5af3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 5 deletions

View File

@ -27,6 +27,15 @@ class NetworkManager extends EventEmitter {
this._frameManager = frameManager; this._frameManager = frameManager;
} }
async setExtraHTTPHeaders(headers) {
const array = [];
for (const [name, value] of Object.entries(headers)) {
assert(helper.isString(value), `Expected value of header "${name}" to be String, but "${typeof value}" is found.`);
array.push({name, value});
}
await this._session.send('Network.setExtraHTTPHeaders', {headers: array});
}
async setRequestInterception(enabled) { async setRequestInterception(enabled) {
await this._session.send('Network.setRequestInterception', {enabled}); await this._session.send('Network.setRequestInterception', {enabled});
} }

View File

@ -77,6 +77,10 @@ class Page extends EventEmitter {
await this._networkManager.setRequestInterception(enabled); await this._networkManager.setRequestInterception(enabled);
} }
async setExtraHTTPHeaders(headers) {
await this._networkManager.setExtraHTTPHeaders(headers);
}
/** /**
* @param {(string|Function)} urlOrPredicate * @param {(string|Function)} urlOrPredicate
* @param {!{timeout?: number}=} options * @param {!{timeout?: number}=} options

View File

@ -9,7 +9,7 @@
"node": ">=8.9.4" "node": ">=8.9.4"
}, },
"puppeteer": { "puppeteer": {
"firefox_revision": "98116977b3f0c936c92e917bdd571c340167a536" "firefox_revision": "e78e4cefab9d40e70bb80b3e649dcba7a7c8ee8f"
}, },
"scripts": { "scripts": {
"install": "node install.js", "install": "node install.js",

View File

@ -429,7 +429,7 @@ module.exports.addTests = function({testRunner, expect, CHROME}) {
await page.setRequestInterception(false); await page.setRequestInterception(false);
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
}); });
it_fails_ffox('should show custom HTTP headers', async({page, server}) => { it('should show custom HTTP headers', async({page, server}) => {
await page.setExtraHTTPHeaders({ await page.setExtraHTTPHeaders({
foo: 'bar' foo: 'bar'
}); });
@ -441,7 +441,7 @@ module.exports.addTests = function({testRunner, expect, CHROME}) {
const response = await page.goto(server.EMPTY_PAGE); const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok()).toBe(true); expect(response.ok()).toBe(true);
}); });
it_fails_ffox('should works with customizing referer headers', async({page, server}) => { it('should works with customizing referer headers', async({page, server}) => {
await page.setExtraHTTPHeaders({ 'referer': server.EMPTY_PAGE }); await page.setExtraHTTPHeaders({ 'referer': server.EMPTY_PAGE });
await page.setRequestInterception(true); await page.setRequestInterception(true);
page.on('request', request => { page.on('request', request => {
@ -477,7 +477,7 @@ module.exports.addTests = function({testRunner, expect, CHROME}) {
expect(failedRequest).toBeTruthy(); expect(failedRequest).toBeTruthy();
expect(failedRequest.failure().errorText).toBe('net::ERR_INTERNET_DISCONNECTED'); expect(failedRequest.failure().errorText).toBe('net::ERR_INTERNET_DISCONNECTED');
}); });
it_fails_ffox('should send referer', async({page, server}) => { it('should send referer', async({page, server}) => {
await page.setExtraHTTPHeaders({ await page.setExtraHTTPHeaders({
referer: 'http://google.com/' referer: 'http://google.com/'
}); });
@ -744,7 +744,7 @@ module.exports.addTests = function({testRunner, expect, CHROME}) {
}); });
}); });
describe_fails_ffox('Page.setExtraHTTPHeaders', function() { describe('Page.setExtraHTTPHeaders', function() {
it('should work', async({page, server}) => { it('should work', async({page, server}) => {
await page.setExtraHTTPHeaders({ await page.setExtraHTTPHeaders({
foo: 'bar' foo: 'bar'