Documentation
¶
Overview ¶
Package httputil offers functions to read and download files via HTTP.
Index ¶
- Variables
- func DownloadBinary(originURL, destDir, destFile string) (string, error)
- func MaybeDownload(bazeliskHome, url, filename, description, token string, merger ContentMerger) ([]byte, error)
- func ReadRemoteFile(url string, token string) ([]byte, http.Header, error)
- type Clock
- type ContentMerger
- type FakeTransport
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultTransport specifies the http.RoundTripper that is used for any network traffic, and may be replaced with a dummy implementation for unit testing. DefaultTransport = http.DefaultTransport UserAgent = "Bazelisk" RetryClock = Clock(&realClock{}) MaxRetries = 4 // MaxRequestDuration defines the maximum amount of time that a request and its retries may take in total MaxRequestDuration = time.Second * 10 )
Functions ¶
func DownloadBinary ¶
DownloadBinary downloads a file from the given URL into the specified location, marks it executable and returns its full path.
func MaybeDownload ¶
func MaybeDownload(bazeliskHome, url, filename, description, token string, merger ContentMerger) ([]byte, error)
MaybeDownload downloads a file from the given url and caches the result under bazeliskHome. It skips the download if the file already exists and is not outdated. Parameter ´description´ is only used to provide better error messages.
func ReadRemoteFile ¶
ReadRemoteFile returns the contents of the given file, using the supplied Authorization token, if set. It also returns the HTTP headers. If the request fails with a transient error it will retry the request for at most MaxRetries times. It obeys HTTP headers such as "Retry-After" when calculating the start time of the next attempt. If no such header is present, it uses an exponential backoff strategy.
Types ¶
type ContentMerger ¶ added in v1.9.0
type FakeTransport ¶ added in v1.10.1
type FakeTransport struct {
// contains filtered or unexported fields
}
func NewFakeTransport ¶ added in v1.10.1
func NewFakeTransport() *FakeTransport