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