2016-02-22 14:44:12 -05:00
|
|
|
package cleanhttp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/http"
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
"runtime"
|
2016-02-22 14:44:12 -05:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
// DefaultTransport returns a new http.Transport with similar default values to
|
|
|
|
// http.DefaultTransport, but with idle connections and keepalives disabled.
|
2016-02-22 14:44:12 -05:00
|
|
|
func DefaultTransport() *http.Transport {
|
|
|
|
transport := DefaultPooledTransport()
|
|
|
|
transport.DisableKeepAlives = true
|
|
|
|
transport.MaxIdleConnsPerHost = -1
|
|
|
|
return transport
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultPooledTransport returns a new http.Transport with similar default
|
|
|
|
// values to http.DefaultTransport. Do not use this for transient transports as
|
|
|
|
// it can leak file descriptors over time. Only use this for transports that
|
|
|
|
// will be re-used for the same host(s).
|
|
|
|
func DefaultPooledTransport() *http.Transport {
|
|
|
|
transport := &http.Transport{
|
|
|
|
Proxy: http.ProxyFromEnvironment,
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
DialContext: (&net.Dialer{
|
2016-02-22 14:44:12 -05:00
|
|
|
Timeout: 30 * time.Second,
|
|
|
|
KeepAlive: 30 * time.Second,
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
DualStack: true,
|
|
|
|
}).DialContext,
|
|
|
|
MaxIdleConns: 100,
|
|
|
|
IdleConnTimeout: 90 * time.Second,
|
|
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
|
|
|
ExpectContinueTimeout: 1 * time.Second,
|
|
|
|
MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1,
|
2016-02-22 14:44:12 -05:00
|
|
|
}
|
|
|
|
return transport
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultClient returns a new http.Client with similar default values to
|
|
|
|
// http.Client, but with a non-shared Transport, idle connections disabled, and
|
|
|
|
// keepalives disabled.
|
|
|
|
func DefaultClient() *http.Client {
|
|
|
|
return &http.Client{
|
|
|
|
Transport: DefaultTransport(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
// DefaultPooledClient returns a new http.Client with similar default values to
|
|
|
|
// http.Client, but with a shared Transport. Do not use this function for
|
|
|
|
// transient clients as it can leak file descriptors over time. Only use this
|
|
|
|
// for clients that will be re-used for the same host(s).
|
2016-02-22 14:44:12 -05:00
|
|
|
func DefaultPooledClient() *http.Client {
|
|
|
|
return &http.Client{
|
|
|
|
Transport: DefaultPooledTransport(),
|
|
|
|
}
|
|
|
|
}
|