feat: add ability to close connections for a session (#24945)

These methods are needed for closing all idle and in-flight connections after
switching to another proxy from same origin for a session, otherwise
these connections may be reused for future requests which is
unexpected for most of users.
This commit is contained in:
LuoJinghua 2020-10-09 00:45:36 +08:00 committed by GitHub
parent fb11a12d5b
commit e4213e326b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View file

@ -295,6 +295,9 @@ Sets the proxy settings.
When `pacScript` and `proxyRules` are provided together, the `proxyRules`
option is ignored and `pacScript` configuration is applied.
You may need `ses.closeAllConnections` to close currently in flight connections to prevent
pooled sockets using previous proxy from being reused by future requests.
The `proxyRules` has to follow the rules below:
```sh
@ -404,6 +407,12 @@ window.webContents.session.enableNetworkEmulation({ offline: true })
Preconnects the given number of sockets to an origin.
#### `ses.closeAllConnections()`
Returns `Promise<void>` - Resolves when all connections are closed.
**Note:** It will terminate / fail all requests currently in flight.
#### `ses.disableNetworkEmulation()`
Disables any network emulation already active for the `session`. Resets to