Skip to content

Commit

Permalink
fix(network): don't disable cache for auth challenge (#6962)
Browse files Browse the repository at this point in the history
* fix(network): don't disable cache for auth challenge

* test: page.authenticate does not disable caching

* fix(network): _protocolRequestInterceptionEnabled -> _userRequestInterceptionEnabled

* style(test): fix line breaks

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
  • Loading branch information
Androbin and mathiasbynens committed Mar 15, 2021
1 parent 56f17fe commit 1c2479a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/common/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ export class NetworkManager extends EventEmitter {
async _updateProtocolCacheDisabled(): Promise<void> {
await this._client.send('Network.setCacheDisabled', {
cacheDisabled:
this._userCacheDisabled || this._protocolRequestInterceptionEnabled,
this._userCacheDisabled || this._userRequestInterceptionEnabled,
});
}

_onRequestWillBeSent(event: Protocol.Network.RequestWillBeSentEvent): void {
// Request interception doesn't happen for data URLs with Network Service.
if (
this._protocolRequestInterceptionEnabled &&
this._userRequestInterceptionEnabled &&
!event.request.url.startsWith('data:')
) {
const requestId = event.requestId;
Expand Down
23 changes: 23 additions & 0 deletions test/network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,5 +569,28 @@ describe('network', function () {
response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
expect(response.status()).toBe(401);
});
it('should not disable caching', async () => {
const { page, server } = getTestState();

// Use unique user/password since Chrome caches credentials per origin.
server.setAuth('/cached/one-style.css', 'user4', 'pass4');
server.setAuth('/cached/one-style.html', 'user4', 'pass4');
await page.authenticate({
username: 'user4',
password: 'pass4',
});

const responses = new Map();
page.on('response', (r) => responses.set(r.url().split('/').pop(), r));

// Load and re-load to make sure it's cached.
await page.goto(server.PREFIX + '/cached/one-style.html');
await page.reload();

expect(responses.get('one-style.css').status()).toBe(200);
expect(responses.get('one-style.css').fromCache()).toBe(true);
expect(responses.get('one-style.html').status()).toBe(304);
expect(responses.get('one-style.html').fromCache()).toBe(false);
});
});
});

0 comments on commit 1c2479a

Please sign in to comment.