mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-13 06:06:44 +00:00
fix: ensure doh connections are closed when it is disabled
This commit is contained in:
@ -31,6 +31,8 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
|
|||||||
* Handle double charset better by using local ParseMediaType instead of mime.ParseMediaType
|
* Handle double charset better by using local ParseMediaType instead of mime.ParseMediaType
|
||||||
* Don't remove log dir
|
* Don't remove log dir
|
||||||
* GODT-422 Fix element not found (avoid listing credentials, prefer getting)
|
* GODT-422 Fix element not found (avoid listing credentials, prefer getting)
|
||||||
|
* GODT-404 Don't keep connections to proxy servers alive if user disables DoH
|
||||||
|
* Ensure DoH is used at startup to load users for the initial auth
|
||||||
|
|
||||||
## [v1.2.7] Donghai-hotfix - beta (2020-05-07)
|
## [v1.2.7] Donghai-hotfix - beta (2020-05-07)
|
||||||
|
|
||||||
|
|||||||
@ -53,6 +53,12 @@ func New(
|
|||||||
clientManager users.ClientManager,
|
clientManager users.ClientManager,
|
||||||
credStorer users.CredentialsStorer,
|
credStorer users.CredentialsStorer,
|
||||||
) *Bridge {
|
) *Bridge {
|
||||||
|
// Allow DoH before starting the app if the user has previously set this setting.
|
||||||
|
// This allows us to start even if protonmail is blocked.
|
||||||
|
if pref.GetBool(preferences.AllowProxyKey) {
|
||||||
|
clientManager.AllowProxy()
|
||||||
|
}
|
||||||
|
|
||||||
storeFactory := newStoreFactory(config, panicHandler, clientManager, eventListener)
|
storeFactory := newStoreFactory(config, panicHandler, clientManager, eventListener)
|
||||||
u := users.New(config, panicHandler, eventListener, clientManager, credStorer, storeFactory)
|
u := users.New(config, panicHandler, eventListener, clientManager, credStorer, storeFactory)
|
||||||
b := &Bridge{
|
b := &Bridge{
|
||||||
@ -62,12 +68,6 @@ func New(
|
|||||||
clientManager: clientManager,
|
clientManager: clientManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow DoH before starting the app if the user has previously set this setting.
|
|
||||||
// This allows us to start even if protonmail is blocked.
|
|
||||||
if pref.GetBool(preferences.AllowProxyKey) {
|
|
||||||
b.AllowProxy()
|
|
||||||
}
|
|
||||||
|
|
||||||
if pref.GetBool(preferences.FirstStartKey) {
|
if pref.GetBool(preferences.FirstStartKey) {
|
||||||
b.SendMetric(metrics.New(metrics.Setup, metrics.FirstStart, metrics.Label(config.GetVersion())))
|
b.SendMetric(metrics.New(metrics.Setup, metrics.FirstStart, metrics.Label(config.GetVersion())))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -198,6 +198,10 @@ func (c *client) clearKeys() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *client) CloseConnections() {
|
||||||
|
c.hc.CloseIdleConnections()
|
||||||
|
}
|
||||||
|
|
||||||
// Do makes an API request. It does not check for HTTP status code errors.
|
// Do makes an API request. It does not check for HTTP status code errors.
|
||||||
func (c *client) Do(req *http.Request, retryUnauthorized bool) (res *http.Response, err error) {
|
func (c *client) Do(req *http.Request, retryUnauthorized bool) (res *http.Response, err error) {
|
||||||
// Copy the request body in case we need to retry it.
|
// Copy the request body in case we need to retry it.
|
||||||
|
|||||||
@ -33,6 +33,7 @@ type Client interface {
|
|||||||
Logout()
|
Logout()
|
||||||
DeleteAuth() error
|
DeleteAuth() error
|
||||||
IsConnected() bool
|
IsConnected() bool
|
||||||
|
CloseConnections()
|
||||||
ClearData()
|
ClearData()
|
||||||
|
|
||||||
CurrentUser() (*User, error)
|
CurrentUser() (*User, error)
|
||||||
|
|||||||
@ -230,6 +230,10 @@ func (cm *ClientManager) DisallowProxy() {
|
|||||||
|
|
||||||
cm.allowProxy = false
|
cm.allowProxy = false
|
||||||
cm.host = rootURL
|
cm.host = rootURL
|
||||||
|
|
||||||
|
for _, client := range cm.clients {
|
||||||
|
client.CloseConnections()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsProxyEnabled returns whether we are currently proxying requests.
|
// IsProxyEnabled returns whether we are currently proxying requests.
|
||||||
|
|||||||
@ -137,6 +137,18 @@ func (mr *MockClientMockRecorder) ClearData() *gomock.Call {
|
|||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClearData", reflect.TypeOf((*MockClient)(nil).ClearData))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClearData", reflect.TypeOf((*MockClient)(nil).ClearData))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseConnections mocks base method
|
||||||
|
func (m *MockClient) CloseConnections() {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
m.ctrl.Call(m, "CloseConnections")
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloseConnections indicates an expected call of CloseConnections
|
||||||
|
func (mr *MockClientMockRecorder) CloseConnections() *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseConnections", reflect.TypeOf((*MockClient)(nil).CloseConnections))
|
||||||
|
}
|
||||||
|
|
||||||
// CountMessages mocks base method
|
// CountMessages mocks base method
|
||||||
func (m *MockClient) CountMessages(arg0 string) ([]*pmapi.MessagesCount, error) {
|
func (m *MockClient) CountMessages(arg0 string) ([]*pmapi.MessagesCount, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
|
|||||||
@ -66,6 +66,10 @@ func New(controller *Controller, userID string) *FakePMAPI {
|
|||||||
return fakePMAPI
|
return fakePMAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *FakePMAPI) CloseConnections() {
|
||||||
|
// NOOP
|
||||||
|
}
|
||||||
|
|
||||||
func (api *FakePMAPI) checkAndRecordCall(method method, path string, request interface{}) error {
|
func (api *FakePMAPI) checkAndRecordCall(method method, path string, request interface{}) error {
|
||||||
if err := api.checkInternetAndRecordCall(method, path, request); err != nil {
|
if err := api.checkInternetAndRecordCall(method, path, request); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user