fix(network): don't disable cache for auth challenge (#6962)

* 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>
This commit is contained in:
Robin Richtsfeld 2021-03-15 08:02:07 +01:00 committed by GitHub
parent 56f17fe481
commit 1c2479a6cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -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;

View File

@ -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);
});
});
});