mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
optimize cookies
This commit is contained in:
@@ -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
2
jar.go
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user