Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setRequestInterception and setExtraHTTPHeaders not working together (#1729) #1734

Merged
merged 2 commits into from Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/NetworkManager.js
Expand Up @@ -569,12 +569,16 @@ function generateRequestHash(request) {
};

if (!normalizedURL.startsWith('data:')) {
const headers = Object.keys(request.headers);
headers.sort();
for (const header of headers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please minimize the change? I believe you can add a header.toLowerCase() as the first line in the loop:

for (let header of headers) {
  header = header.toLowerCase();
  if (key === 'accept' || key === 'referer' ...)
}

if (header === 'Accept' || header === 'Referer' || header === 'X-DevTools-Emulate-Network-Conditions-Client-Id')
const headers = {};
for (const key of Object.keys(request.headers))
// Need to consider uncapitalized headers. See https://github.com/GoogleChrome/puppeteer/issues/1729
headers[key.toLowerCase()] = request.headers[key];
const headerKeys = Object.keys(headers);
headerKeys.sort();
for (const key of headerKeys) {
if (key === 'accept' || key === 'referer' || key === 'x-devtools-emulate-network-conditions-client-id')
continue;
hash.headers[header] = request.headers[header];
hash.headers[key] = headers[key];
}
}
return JSON.stringify(hash);
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Expand Up @@ -1321,6 +1321,16 @@ describe('Page', function() {
const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok()).toBe(true);
});
it('should works with customizing referer headers', async({page, server}) => {
await page.setExtraHTTPHeaders({ 'referer': server.EMPTY_PAGE });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good test, thank you.

await page.setRequestInterception(true);
page.on('request', request => {
expect(request.headers()['referer']).toBe(server.EMPTY_PAGE);
request.continue();
});
const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok()).toBe(true);
});
it('should be abortable', async({page, server}) => {
await page.setRequestInterception(true);
page.on('request', request => {
Expand Down