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

This patch starts lowering header keys while generating request hashes.

Fixes #1729.
This commit is contained in:
yujiosaka 2018-01-10 09:52:28 +09:00 committed by Andrey Lushnikov
parent dcc1b24395
commit 5843f6f775
2 changed files with 15 additions and 3 deletions

View File

@ -571,10 +571,12 @@ function generateRequestHash(request) {
if (!normalizedURL.startsWith('data:')) { if (!normalizedURL.startsWith('data:')) {
const headers = Object.keys(request.headers); const headers = Object.keys(request.headers);
headers.sort(); headers.sort();
for (const header of headers) { for (let header of headers) {
if (header === 'Accept' || header === 'Referer' || header === 'X-DevTools-Emulate-Network-Conditions-Client-Id') const headerValue = request.headers[header];
header = header.toLowerCase();
if (header === 'accept' || header === 'referer' || header === 'x-devtools-emulate-network-conditions-client-id')
continue; continue;
hash.headers[header] = request.headers[header]; hash.headers[header] = headerValue;
} }
} }
return JSON.stringify(hash); return JSON.stringify(hash);

View File

@ -1332,6 +1332,16 @@ describe('Page', function() {
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('should works with customizing referer headers', async({page, server}) => {
await page.setExtraHTTPHeaders({ 'referer': server.EMPTY_PAGE });
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}) => { it('should be abortable', async({page, server}) => {
await page.setRequestInterception(true); await page.setRequestInterception(true);
page.on('request', request => { page.on('request', request => {