mirror of
https://github.com/rclone/rclone.git
synced 2025-12-16 00:04:40 +00:00
Redo http Transport code
* Insert User-Agent in Transport - fixes #199 * Update timeouts to use Context * Modernise transport
This commit is contained in:
34
fs/http_new.go
Normal file
34
fs/http_new.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// HTTP parts go1.7+
|
||||
|
||||
//+build go1.7
|
||||
|
||||
package fs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 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,
|
||||
}
|
||||
c, err := dialer.DialContext(ctx, network, address)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
return newTimeoutConn(c, 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.IdleConnTimeout = 60 * time.Second
|
||||
t.ExpectContinueTimeout = ci.ConnectTimeout
|
||||
}
|
||||
Reference in New Issue
Block a user