mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
sync
This commit is contained in:
67
dial.go
67
dial.go
@@ -225,29 +225,38 @@ func (obj *DialClient) verifyProxyToRemote(ctx context.Context, option *RequestO
|
||||
})
|
||||
}
|
||||
}
|
||||
switch proxyUrl.Scheme {
|
||||
case "http", "https":
|
||||
err = obj.clientVerifyHttps(ctx, conn, proxyUrl, remoteUrl)
|
||||
if option.Logger != nil {
|
||||
option.Logger(Log{
|
||||
Id: option.requestId,
|
||||
Time: time.Now(),
|
||||
Type: LogType_ProxyConnectRemote,
|
||||
Msg: remoteUrl.String(),
|
||||
})
|
||||
}
|
||||
case "socks5":
|
||||
err = obj.socks5ProxyWithConn(ctx, conn, proxyUrl, remoteUrl)
|
||||
if option.Logger != nil {
|
||||
option.Logger(Log{
|
||||
Id: option.requestId,
|
||||
Time: time.Now(),
|
||||
Type: LogType_ProxyTCPConnect,
|
||||
Msg: remoteUrl.String(),
|
||||
})
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
switch proxyUrl.Scheme {
|
||||
case "http", "https":
|
||||
err = obj.clientVerifyHttps(ctx, conn, proxyUrl, remoteUrl)
|
||||
if option.Logger != nil {
|
||||
option.Logger(Log{
|
||||
Id: option.requestId,
|
||||
Time: time.Now(),
|
||||
Type: LogType_ProxyConnectRemote,
|
||||
Msg: remoteUrl.String(),
|
||||
})
|
||||
}
|
||||
case "socks5":
|
||||
err = obj.clientVerifySocks5(conn, proxyUrl, remoteUrl)
|
||||
if option.Logger != nil {
|
||||
option.Logger(Log{
|
||||
Id: option.requestId,
|
||||
Time: time.Now(),
|
||||
Type: LogType_ProxyTCPConnect,
|
||||
Msg: remoteUrl.String(),
|
||||
})
|
||||
}
|
||||
}
|
||||
close(done)
|
||||
}()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return conn, context.Cause(ctx)
|
||||
case <-done:
|
||||
return conn, err
|
||||
}
|
||||
return conn, err
|
||||
}
|
||||
func (obj *DialClient) loadHost(host string) (string, bool) {
|
||||
msgDataAny, ok := obj.dnsIpData.Load(host)
|
||||
@@ -500,22 +509,6 @@ func (obj *DialClient) Socks5Proxy(ctx context.Context, ctxData *RequestOption,
|
||||
return
|
||||
}
|
||||
}
|
||||
func (obj *DialClient) socks5ProxyWithConn(ctx context.Context, conn net.Conn, proxyUrl *url.URL, remoteUrl *url.URL) (err error) {
|
||||
didVerify := make(chan struct{})
|
||||
go func() {
|
||||
if err = obj.clientVerifySocks5(conn, proxyUrl, remoteUrl); err != nil {
|
||||
conn.Close()
|
||||
}
|
||||
close(didVerify)
|
||||
}()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
conn.Close()
|
||||
return context.Cause(ctx)
|
||||
case <-didVerify:
|
||||
return
|
||||
}
|
||||
}
|
||||
func (obj *DialClient) clientVerifyHttps(ctx context.Context, conn net.Conn, proxyUrl *url.URL, remoteUrl *url.URL) (err error) {
|
||||
hdr := make(http.Header)
|
||||
hdr.Set("User-Agent", tools.UserAgent)
|
||||
|
||||
Reference in New Issue
Block a user