fix: webRequest module should work with file:// protocol (#22903)
* fix: override file:// instead of intercepting * test: webRequest module should work with file:// * fix: service work with file:// url * fix: original_response_headers can be null * fix: only register file:// when necessary
This commit is contained in:
parent
bac1c7f532
commit
e6f2605ad0
6 changed files with 101 additions and 7 deletions
|
@ -2,6 +2,7 @@ import { expect } from 'chai';
|
|||
import * as http from 'http';
|
||||
import * as qs from 'querystring';
|
||||
import * as path from 'path';
|
||||
import * as url from 'url';
|
||||
import * as WebSocket from 'ws';
|
||||
import { ipcMain, protocol, session, WebContents, webContents } from 'electron';
|
||||
import { AddressInfo } from 'net';
|
||||
|
@ -133,11 +134,24 @@ describe('webRequest module', () => {
|
|||
await ajax(defaultURL + 'serverRedirect');
|
||||
await ajax(defaultURL + 'serverRedirect');
|
||||
});
|
||||
|
||||
it('works with file:// protocol', (done) => {
|
||||
ses.webRequest.onBeforeRequest((details, callback) => {
|
||||
callback({ cancel: true });
|
||||
done();
|
||||
});
|
||||
ajax(url.format({
|
||||
pathname: path.join(fixturesPath, 'blank.html').replace(/\\/g, '/'),
|
||||
protocol: 'file',
|
||||
slashes: true
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('webRequest.onBeforeSendHeaders', () => {
|
||||
afterEach(() => {
|
||||
ses.webRequest.onBeforeSendHeaders(null);
|
||||
ses.webRequest.onSendHeaders(null);
|
||||
});
|
||||
|
||||
it('receives details object', async () => {
|
||||
|
@ -192,6 +206,24 @@ describe('webRequest module', () => {
|
|||
});
|
||||
await ajax(defaultURL);
|
||||
});
|
||||
|
||||
it('works with file:// protocol', (done) => {
|
||||
const requestHeaders = {
|
||||
Test: 'header'
|
||||
};
|
||||
ses.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||
callback({ requestHeaders: requestHeaders });
|
||||
});
|
||||
ses.webRequest.onSendHeaders((details) => {
|
||||
expect(details.requestHeaders).to.deep.equal(requestHeaders);
|
||||
done();
|
||||
});
|
||||
ajax(url.format({
|
||||
pathname: path.join(fixturesPath, 'blank.html').replace(/\\/g, '/'),
|
||||
protocol: 'file',
|
||||
slashes: true
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('webRequest.onSendHeaders', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue