Documentation ¶
Overview ¶
Package httputil offers functions to read and download files via HTTP.
Index ¶
- Variables
- func DownloadBinary(originURL, destDir, destFile string, config config.Config) (string, error)
- func MaybeDownload(bazeliskHome, url, filename, description, auth string, merger ContentMerger) ([]byte, error)
- func ReadRemoteFile(url string, auth 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 is passed to every HTTP request as part of the 'User-Agent' header. UserAgent = "Bazelisk" // RetryClock is used for waiting between HTTP request retries. RetryClock = Clock(&realClock{}) // MaxRetries specifies how often non-fatally failing HTTP requests should be retried. MaxRetries = 4 // MaxRequestDuration defines the maximum amount of time that a request and its retries may take in total MaxRequestDuration = time.Second * 30 )
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, auth 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. Parameter `auth` is a value of "Authorization" HTTP header.
func ReadRemoteFile ¶
ReadRemoteFile returns the contents of the given file, using the supplied Authorization header value, 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 Clock ¶ added in v1.10.1
Clock keeps track of time. It can return the current time, as well as move forward by sleeping for a certain period.
type ContentMerger ¶ added in v1.9.0
ContentMerger is a function that merges multiple HTTP payloads into a single message.
type FakeTransport ¶ added in v1.10.1
type FakeTransport struct {
// contains filtered or unexported fields
}
FakeTransport represents a fake http.Transport that returns prerecorded responses.
func NewFakeTransport ¶ added in v1.10.1
func NewFakeTransport() *FakeTransport
NewFakeTransport creates a new FakeTransport instance without any responses.
func (*FakeTransport) AddError ¶ added in v1.20.0
func (ft *FakeTransport) AddError(url string, err error)
AddError stores a error for the given URL.
func (*FakeTransport) AddResponse ¶ added in v1.10.1
func (ft *FakeTransport) AddResponse(url string, status int, body string, headers map[string]string)
AddResponse stores a fake HTTP response for the given URL.