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:
parent
56f17fe481
commit
1c2479a6cd
@ -217,14 +217,14 @@ export class NetworkManager extends EventEmitter {
|
|||||||
async _updateProtocolCacheDisabled(): Promise<void> {
|
async _updateProtocolCacheDisabled(): Promise<void> {
|
||||||
await this._client.send('Network.setCacheDisabled', {
|
await this._client.send('Network.setCacheDisabled', {
|
||||||
cacheDisabled:
|
cacheDisabled:
|
||||||
this._userCacheDisabled || this._protocolRequestInterceptionEnabled,
|
this._userCacheDisabled || this._userRequestInterceptionEnabled,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_onRequestWillBeSent(event: Protocol.Network.RequestWillBeSentEvent): void {
|
_onRequestWillBeSent(event: Protocol.Network.RequestWillBeSentEvent): void {
|
||||||
// Request interception doesn't happen for data URLs with Network Service.
|
// Request interception doesn't happen for data URLs with Network Service.
|
||||||
if (
|
if (
|
||||||
this._protocolRequestInterceptionEnabled &&
|
this._userRequestInterceptionEnabled &&
|
||||||
!event.request.url.startsWith('data:')
|
!event.request.url.startsWith('data:')
|
||||||
) {
|
) {
|
||||||
const requestId = event.requestId;
|
const requestId = event.requestId;
|
||||||
|
@ -569,5 +569,28 @@ describe('network', function () {
|
|||||||
response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
|
response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
|
||||||
expect(response.status()).toBe(401);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user