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:
parent
dcc1b24395
commit
5843f6f775
@ -571,10 +571,12 @@ function generateRequestHash(request) {
|
||||
if (!normalizedURL.startsWith('data:')) {
|
||||
const headers = Object.keys(request.headers);
|
||||
headers.sort();
|
||||
for (const header of headers) {
|
||||
if (header === 'Accept' || header === 'Referer' || header === 'X-DevTools-Emulate-Network-Conditions-Client-Id')
|
||||
for (let header of headers) {
|
||||
const headerValue = request.headers[header];
|
||||
header = header.toLowerCase();
|
||||
if (header === 'accept' || header === 'referer' || header === 'x-devtools-emulate-network-conditions-client-id')
|
||||
continue;
|
||||
hash.headers[header] = request.headers[header];
|
||||
hash.headers[header] = headerValue;
|
||||
}
|
||||
}
|
||||
return JSON.stringify(hash);
|
||||
|
10
test/test.js
10
test/test.js
@ -1332,6 +1332,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 });
|
||||
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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user