diff --git a/http/download.go b/http/download.go index 8f97ccfb..55e7eebb 100644 --- a/http/download.go +++ b/http/download.go @@ -10,6 +10,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/mxk/go-flowrate/flowrate" "github.com/smira/aptly/aptly" @@ -62,12 +63,11 @@ type downloadTask struct { func NewDownloader(threads int, downLimit int64, progress aptly.Progress) aptly.Downloader { transport := http.Transport{} transport.Proxy = http.DefaultTransport.(*http.Transport).Proxy - transport.DialContext = http.DefaultTransport.(*http.Transport).DialContext - transport.MaxIdleConns = http.DefaultTransport.(*http.Transport).MaxIdleConns - transport.IdleConnTimeout = http.DefaultTransport.(*http.Transport).IdleConnTimeout + transport.ResponseHeaderTimeout = 30 * time.Second transport.TLSHandshakeTimeout = http.DefaultTransport.(*http.Transport).TLSHandshakeTimeout transport.ExpectContinueTimeout = http.DefaultTransport.(*http.Transport).ExpectContinueTimeout transport.DisableCompression = true + initTransport(&transport) transport.RegisterProtocol("ftp", &protocol.FTPRoundTripper{}) downloader := &downloaderImpl{ diff --git a/http/download_go16.go b/http/download_go16.go new file mode 100644 index 00000000..f4df5156 --- /dev/null +++ b/http/download_go16.go @@ -0,0 +1,11 @@ +// +build !go1.7 + +package http + +import ( + "net/http" +) + +func initTransport(transport *http.Transport) { + +} diff --git a/http/download_go17.go b/http/download_go17.go new file mode 100644 index 00000000..a69a210c --- /dev/null +++ b/http/download_go17.go @@ -0,0 +1,13 @@ +// +build go1.7 + +package http + +import ( + "net/http" +) + +func initTransport(transport *http.Transport) { + transport.DialContext = http.DefaultTransport.(*http.Transport).DialContext + transport.MaxIdleConns = http.DefaultTransport.(*http.Transport).MaxIdleConns + transport.IdleConnTimeout = http.DefaultTransport.(*http.Transport).IdleConnTimeout +}