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

@ -903,6 +903,19 @@ void Session::Preconnect(const gin_helper::Dictionary& options,
url, num_sockets_to_preconnect));
}
v8::Local<v8::Promise> Session::CloseAllConnections() {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
gin_helper::Promise<void> promise(isolate);
auto handle = promise.GetHandle();
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
->GetNetworkContext()
->CloseAllConnections(base::BindOnce(
gin_helper::Promise<void>::ResolvePromise, std::move(promise)));
return handle;
}
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
base::Value Session::GetSpellCheckerLanguages() {
return browser_context_->prefs()
@ -1106,6 +1119,7 @@ gin::ObjectTemplateBuilder Session::GetObjectTemplateBuilder(
&Session::RemoveWordFromSpellCheckerDictionary)
#endif
.SetMethod("preconnect", &Session::Preconnect)
.SetMethod("closeAllConnections", &Session::CloseAllConnections)
.SetProperty("cookies", &Session::Cookies)
.SetProperty("netLog", &Session::NetLog)
.SetProperty("protocol", &Session::Protocol)