2016-09-10 18:17:43 +00:00
|
|
|
// HTTP parts go1.7+
|
|
|
|
|
|
|
|
//+build go1.7
|
|
|
|
|
2018-01-12 16:30:54 +00:00
|
|
|
package fshttp
|
2016-09-10 18:17:43 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
2018-01-12 16:30:54 +00:00
|
|
|
|
|
|
|
"github.com/ncw/rclone/fs"
|
2016-09-10 18:17:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// dial with context and timeouts
|
2018-01-12 16:30:54 +00:00
|
|
|
func dialContextTimeout(ctx context.Context, network, address string, ci *fs.ConfigInfo) (net.Conn, error) {
|
|
|
|
dialer := NewDialer(ci)
|
2016-09-10 18:17:43 +00:00
|
|
|
c, err := dialer.DialContext(ctx, network, address)
|
|
|
|
if err != nil {
|
|
|
|
return c, err
|
|
|
|
}
|
2017-07-23 15:10:23 +00:00
|
|
|
return newTimeoutConn(c, ci.Timeout), nil
|
2016-09-10 18:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise the http.Transport for go1.7+
|
2018-01-12 16:30:54 +00:00
|
|
|
func initTransport(ci *fs.ConfigInfo, t *http.Transport) {
|
|
|
|
t.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
|
|
return dialContextTimeout(ctx, network, addr, ci)
|
|
|
|
}
|
2016-09-10 18:17:43 +00:00
|
|
|
t.IdleConnTimeout = 60 * time.Second
|
|
|
|
t.ExpectContinueTimeout = ci.ConnectTimeout
|
|
|
|
}
|