reghttp

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package reghttp is used for HTTP requests to a registry

Index

Constants

View Source
const (
	DefaultRetryLimit = 5 // number of times a request will be retried

)

Variables

This section is empty.

Functions

func HTTPError

func HTTPError(statusCode int) error

HTTPError returns an error based on the status code.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an HTTP client wrapper. It handles features like authentication, retries, backoff delays, TLS settings.

func NewClient

func NewClient(opts ...Opts) *Client

NewClient returns a client for handling requests.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *Req) (*Resp, error)

Do runs a request, returning the response result.

func (*Client) GetThrottle added in v0.7.2

func (c *Client) GetThrottle(host string) *pqueue.Queue[reqmeta.Data]

GetThrottle returns the current pqueue.Queue for a host used to throttle connections. This can be used to acquire multiple throttles before performing a request across multiple hosts.

type Opts

type Opts func(*Client)

Opts is used to configure client options.

func WithCertDirs

func WithCertDirs(dirs []string) Opts

WithCertDirs adds directories to check for host specific certs.

func WithCertFiles

func WithCertFiles(files []string) Opts

WithCertFiles adds certificates by filename.

func WithCerts

func WithCerts(certs [][]byte) Opts

WithCerts adds certificates.

func WithConfigHostFn added in v0.7.2

func WithConfigHostFn(gch func(string) *config.Host) Opts

WithConfigHostFn adds the callback to request a config.Host struct. The function must normalize the hostname for Docker Hub support.

func WithDelay

func WithDelay(delayInit time.Duration, delayMax time.Duration) Opts

WithDelay initial time to wait between retries (increased with exponential backoff).

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Opts

WithHTTPClient uses a specific http client with retryable requests.

func WithLog

func WithLog(log *logrus.Logger) Opts

WithLog injects a logrus Logger configuration.

func WithRetryLimit

func WithRetryLimit(rl int) Opts

WithRetryLimit restricts the number of retries (defaults to 5).

func WithTransport

func WithTransport(t *http.Transport) Opts

WithTransport uses a specific http transport with retryable requests.

func WithUserAgent

func WithUserAgent(ua string) Opts

WithUserAgent sets a user agent header.

type Req

type Req struct {
	MetaKind    reqmeta.Kind                  // kind of request for the priority queue
	Host        string                        // registry name, hostname and mirrors will be looked up from host configuration
	Method      string                        // http method to call
	DirectURL   *url.URL                      // url to query, overrides repository, path, and query
	Repository  string                        // repository to scope the request
	Path        string                        // path of the request within a repository
	Query       url.Values                    // url query parameters
	BodyLen     int64                         // length of body to send
	BodyBytes   []byte                        // bytes of the body, overridden by BodyFunc
	BodyFunc    func() (io.ReadCloser, error) // function to return a new body
	Headers     http.Header                   // headers to send in the request
	NoPrefix    bool                          // do not include the repository prefix
	NoMirrors   bool                          // do not send request to a mirror
	ExpectLen   int64                         // expected size of the returned body
	TransactLen int64                         // size of an overall transaction for the priority queue
	IgnoreErr   bool                          // ignore http errors and do not trigger backoffs
}

Req is a request to send to a registry.

type Resp

type Resp struct {
	// contains filtered or unexported fields
}

Resp is used to handle the result of a request.

func (*Resp) Close added in v0.7.2

func (resp *Resp) Close() error

Close frees up resources from the request.

func (*Resp) HTTPResponse

func (resp *Resp) HTTPResponse() *http.Response

HTTPResponse returns the http.Response from the last request.

func (*Resp) Read added in v0.7.2

func (resp *Resp) Read(b []byte) (int, error)

Read provides a retryable read from the body of the response.

func (*Resp) Seek added in v0.7.2

func (resp *Resp) Seek(offset int64, whence int) (int64, error)

Seek provides a limited ability seek within the request response.

Jump to

Keyboard shortcuts

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