Fix Request Interception (#565)

It turned out that either Network.requestIntercepted or
Network.requestWillBeSent occasionally report encoded URL.

This patch starts decoding URL's when generating request hash.

Fixes #558.
This commit is contained in:
Andrey Lushnikov 2017-08-27 12:41:09 -07:00 committed by GitHub
parent ea4f8d78fc
commit e921a1cc21
3 changed files with 31 additions and 1 deletions

View File

@ -122,6 +122,13 @@ class Multimap {
return result;
}
/**
* @return {!Array<!K>}
*/
keysArray() {
return Array.from(this._map.keys());
}
clear() {
this._map.clear();
}

View File

@ -340,7 +340,8 @@ helper.tracePublicAPI(Response);
*/
function generateRequestHash(request) {
const hash = {
url: request.url,
// Decoding is necessary to normalize URLs. @see crbug.com/759388
url: decodeURI(request.url),
method: request.method,
postData: request.postData,
headers: {},

View File

@ -938,6 +938,28 @@ describe('Page', function() {
expect(requests.length).toBe(1);
expect(requests[0].url).toBe(EMPTY_PAGE);
}));
it('should work with encoded URLs', SX(async function() {
// The requestWillBeSent will report encoded URL, whereas interception will
// report URL as-is. @see crbug.com/759388
await page.setRequestInterceptionEnabled(true);
page.on('request', request => request.continue());
const response = await page.goto(PREFIX + '/some nonexisting page');
expect(response.status).toBe(404);
}));
it('should work with encoded URLs - 2', SX(async function() {
// The requestWillBeSent will report URL as-is, whereas interception will
// report encoded URL for stylesheet. @see crbug.com/759388
await page.setRequestInterceptionEnabled(true);
const requests = [];
page.on('request', request => {
request.continue();
requests.push(request);
});
const response = await page.goto(`data:text/html,<link rel="stylesheet" href="${PREFIX}/fonts?helvetica|arial"/>`);
expect(response.status).toBe(200);
expect(requests.length).toBe(2);
expect(requests[1].response().status).toBe(404);
}));
});
describe('Page.Events.Dialog', function() {