optimize cookies

This commit is contained in:
bxd
2023-10-30 15:12:22 +08:00
parent ed78b8c6cd
commit 2c88968672
3 changed files with 29 additions and 2 deletions

View File

@@ -200,10 +200,16 @@ func (obj *Client) SetGetProxy(getProxy func(ctx context.Context, url *url.URL)
func (obj *Client) CloseIdleConnections() {
obj.transport.CloseIdleConnections()
}
func (obj *Client) CloseConnections() {
obj.transport.CloseConnections()
}
func (obj *Client) CloseIdleConnectionsWithProxy(proxy string) {
obj.transport.CloseIdleConnectionsWithProxy(proxy)
}
func (obj *Client) CloseConnectionsWithProxy(proxy string) {
obj.transport.CloseConnectionsWithProxy(proxy)
}
func (obj *Client) Close() {
obj.CloseConnections()
obj.cnl()

2
jar.go
View File

@@ -60,7 +60,7 @@ func (obj *Jar) SetCookies(href string, cookies ...any) error {
cook.Path = "/"
}
if cook.Domain == "" {
cook.Domain, err = publicsuffix.EffectiveTLDPlusOne(u.Hostname())
cook.Domain, _ = publicsuffix.PublicSuffix(u.Hostname())
if err != nil {
return err
}

View File

@@ -664,6 +664,27 @@ func (obj *RoundTripper) CloseConnections() {
}
}
func (obj *RoundTripper) CloseIdleConnectionsWithProxy(proxy string) {
obj.connsLock.Lock()
defer obj.connsLock.Unlock()
for key, pool := range obj.connPools {
if key.proxy == proxy {
pool.Close()
delete(obj.connPools, key)
}
}
}
func (obj *RoundTripper) CloseConnectionsWithProxy(proxy string) {
obj.connsLock.Lock()
defer obj.connsLock.Unlock()
for key, pool := range obj.connPools {
if key.proxy == proxy {
pool.Close()
delete(obj.connPools, key)
}
}
}
func (obj *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
ctxData := req.Context().Value(keyPrincipalID).(*reqCtxData)
if ctxData.requestCallBack != nil {