httputil

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = &http.Client{
	Transport: &LoggerTransport{
		Transport: &http.Transport{
			Dial: (&net.Dialer{
				Timeout: 5 * time.Second,
			}).Dial,
			TLSHandshakeTimeout: 5 * time.Second,
		},
	},
}

DefaultClient is a HTTP client with sane defaults.

Functions

func Download

func Download(ctx context.Context, url string) (io.ReadCloser, error)

Download returns a reader for the file at url. It is the caller's responsibility to close the returned reader.

func DownloadIfNotExist

func DownloadIfNotExist(ctx context.Context, path string, url string) error

DownloadIfNotExist writes the resource at url to the file at path if it does not already exist. If no extension is specified in path, the extension will be modified to mirror that of the resource at url.

Types

type LoggerTransport

type LoggerTransport struct {
	*http.Transport
}

LoggerTransport logs outgoing requests for debugging purposes.

func (*LoggerTransport) RoundTrip

func (t *LoggerTransport) RoundTrip(r *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL