Skip to content

Commit

Permalink
fix(network): be able to remove headers using request.continue (#4797)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored and aslushnikov committed Aug 5, 2019
1 parent 4acce55 commit b9b6ca1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion experimental/puppeteer-firefox/lib/NetworkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
6 changes: 4 additions & 2 deletions lib/NetworkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,10 @@ class SecurityDetails {
*/
function headersArray(headers) {
const result = [];
for (const name in headers)
result.push({name, value: headers[name] + ''});
for (const name in headers) {
if (!Object.is(headers[name], undefined))
result.push({name, value: headers[name] + ''});
}
return result;
}

Expand Down
18 changes: 18 additions & 0 deletions test/requestinterception.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit b9b6ca1

Please sign in to comment.