Add --bind flag for choosing the local addr on outgoing connections - fixes #1087
Supported by all remotes except FTP.
This commit is contained in:
+4
-10
@@ -7,25 +7,19 @@ package fs
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// dial with timeouts
|
||||
func dialTimeout(network, address string, connectTimeout, timeout time.Duration) (net.Conn, error) {
|
||||
dialer := net.Dialer{
|
||||
Timeout: connectTimeout,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}
|
||||
func (ci *ConfigInfo) dialTimeout(network, address string) (net.Conn, error) {
|
||||
dialer := ci.NewDialer()
|
||||
c, err := dialer.Dial(network, address)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
return newTimeoutConn(c, timeout), nil
|
||||
return newTimeoutConn(c, ci.Timeout), nil
|
||||
}
|
||||
|
||||
// Initialise the http.Transport for pre go1.7
|
||||
func (ci *ConfigInfo) initTransport(t *http.Transport) {
|
||||
t.Dial = func(network, address string) (net.Conn, error) {
|
||||
return dialTimeout(network, address, ci.ConnectTimeout, ci.Timeout)
|
||||
}
|
||||
t.Dial = dialTimeout
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user