fix(network): be able to remove headers using request.continue (#4797)

I think this was a regression caused here https://github.com/GoogleChrome/puppeteer/pull/4265/files#diff-d2ac7cb061b0c51644d0a5d6140e3a32R446

Fix #4743
This commit is contained in:
Darío Kondratiuk 2019-08-05 19:26:17 -03:00 committed by Andrey Lushnikov
parent 4acce550c4
commit b9b6ca1825
3 changed files with 23 additions and 3 deletions

View File

@ -158,7 +158,7 @@ class Request {
} = overrides;
await this._session.send('Network.resumeSuspendedRequest', {
requestId: this._id,
headers: headers ? Object.entries(headers).map(([name, value]) => ({name, value})) : undefined,
headers: headers ? Object.entries(headers).filter(([, value]) => !Object.is(value, undefined)).map(([name, value]) => ({name, value})) : undefined,
}).catch(error => {
debugError(error);
});

View File

@ -723,8 +723,10 @@ class SecurityDetails {
*/
function headersArray(headers) {
const result = [];
for (const name in headers)
for (const name in headers) {
if (!Object.is(headers[name], undefined))
result.push({name, value: headers[name] + ''});
}
return result;
}

View File

@ -72,6 +72,24 @@ module.exports.addTests = function({testRunner, expect, CHROME}) {
});
await page.goto(server.PREFIX + '/rrredirect');
});
// @see https://github.com/GoogleChrome/puppeteer/issues/4743
it('should be able to remove headers', async({page, server}) => {
await page.setRequestInterception(true);
page.on('request', request => {
const headers = Object.assign({}, request.headers(), {
foo: 'bar',
origin: undefined, // remove "origin" header
});
request.continue({ headers });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/empty.html'),
page.goto(server.PREFIX + '/empty.html')
]);
expect(serverRequest.headers.origin).toBe(undefined);
});
it('should contain referer header', async({page, server}) => {
await page.setRequestInterception(true);
const requests = [];