Add --bind flag for choosing the local addr on outgoing connections - fixes #1087

Supported by all remotes except FTP.
This commit is contained in:
Nick Craig-Wood
2017-07-23 16:27:39 +01:00
parent 8b30023f0d
commit 9f24639568
7 changed files with 61 additions and 20 deletions
+4 -9
View File
@@ -12,23 +12,18 @@ import (
)
// dial with context and timeouts
func dialContextTimeout(ctx context.Context, network, address string, connectTimeout, timeout time.Duration) (net.Conn, error) {
dialer := net.Dialer{
Timeout: connectTimeout,
KeepAlive: 30 * time.Second,
}
func (ci *ConfigInfo) dialContextTimeout(ctx context.Context, network, address string) (net.Conn, error) {
dialer := ci.NewDialer()
c, err := dialer.DialContext(ctx, network, address)
if err != nil {
return c, err
}
return newTimeoutConn(c, timeout), nil
return newTimeoutConn(c, ci.Timeout), nil
}
// Initialise the http.Transport for go1.7+
func (ci *ConfigInfo) initTransport(t *http.Transport) {
t.DialContext = func(ctx context.Context, network, address string) (net.Conn, error) {
return dialContextTimeout(ctx, network, address, ci.ConnectTimeout, ci.Timeout)
}
t.DialContext = ci.dialContextTimeout
t.IdleConnTimeout = 60 * time.Second
t.ExpectContinueTimeout = ci.ConnectTimeout
}