mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 15:46:44 +00:00
feat: persistent cookies
This commit is contained in:
@ -127,7 +127,7 @@ type client struct {
|
||||
func newClient(cm *ClientManager, userID string) *client {
|
||||
return &client{
|
||||
cm: cm,
|
||||
hc: getHTTPClient(cm.config, cm.roundTripper),
|
||||
hc: getHTTPClient(cm.config, cm.roundTripper, cm.cookieJar),
|
||||
userID: userID,
|
||||
requestLocker: &sync.Mutex{},
|
||||
keyRingLock: &sync.Mutex{},
|
||||
@ -137,10 +137,11 @@ func newClient(cm *ClientManager, userID string) *client {
|
||||
}
|
||||
|
||||
// getHTTPClient returns a http client configured by the given client config and using the given transport.
|
||||
func getHTTPClient(cfg *ClientConfig, rt http.RoundTripper) (hc *http.Client) {
|
||||
func getHTTPClient(cfg *ClientConfig, rt http.RoundTripper, jar http.CookieJar) (hc *http.Client) {
|
||||
return &http.Client{
|
||||
Timeout: cfg.Timeout,
|
||||
Transport: rt,
|
||||
Jar: jar,
|
||||
Timeout: cfg.Timeout,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -41,6 +41,7 @@ type ClientManager struct {
|
||||
|
||||
clients map[string]Client
|
||||
clientsLocker sync.Locker
|
||||
cookieJar http.CookieJar
|
||||
|
||||
tokens map[string]string
|
||||
tokensLocker sync.Locker
|
||||
@ -126,6 +127,11 @@ func (cm *ClientManager) SetClientConstructor(f func(userID string) Client) {
|
||||
cm.newClient = f
|
||||
}
|
||||
|
||||
// SetCookieJar sets the cookie jar given to clients.
|
||||
func (cm *ClientManager) SetCookieJar(jar http.CookieJar) {
|
||||
cm.cookieJar = jar
|
||||
}
|
||||
|
||||
// SetRoundTripper sets the roundtripper used by clients created by this client manager.
|
||||
func (cm *ClientManager) SetRoundTripper(rt http.RoundTripper) {
|
||||
cm.roundTripper = rt
|
||||
@ -145,9 +151,11 @@ func (cm *ClientManager) GetClient(userID string) Client {
|
||||
return client
|
||||
}
|
||||
|
||||
cm.clients[userID] = cm.newClient(userID)
|
||||
client := cm.newClient(userID)
|
||||
|
||||
return cm.clients[userID]
|
||||
cm.clients[userID] = client
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
// GetAnonymousClient returns an anonymous client.
|
||||
@ -303,7 +311,7 @@ var ErrNoInternetConnection = errors.New("no internet connection")
|
||||
// CheckConnection returns an error if there is no internet connection.
|
||||
// This should be moved to the ConnectionManager when it is implemented.
|
||||
func (cm *ClientManager) CheckConnection() error {
|
||||
client := getHTTPClient(cm.config, cm.roundTripper)
|
||||
client := getHTTPClient(cm.config, cm.roundTripper, cm.cookieJar)
|
||||
|
||||
// Do not cumulate timeouts, use goroutines.
|
||||
retStatus := make(chan error)
|
||||
|
||||
Reference in New Issue
Block a user