httpclientutil

package
v0.18.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const HTTPStatusErrorBodyMaxLength = 64 * 1024

HTTPStatusErrorBodyMaxLength specifies the maximum length of HTTPStatusError.Body

Variables

This section is empty.

Functions

func Get

func Get(ctx context.Context, c *http.Client, url string) (*http.Response, error)

Get calls HTTP GET and verifies that the status code is 2XX .

func NewHTTPClientWithSocketPath

func NewHTTPClientWithSocketPath(socketPath string) (*http.Client, error)

NewHTTPClientWithSocketPath creates a client. socketPath is a path to the UNIX socket, without unix:// prefix.

func NewHTTPClientWithVSockPort added in v0.18.0

func NewHTTPClientWithVSockPort(port int) *http.Client

NewHTTPClientWithVSockPort creates a client. port is the port to use for the vsock.

func Successful

func Successful(resp *http.Response) error

Types

type HTTPStatusError

type HTTPStatusError struct {
	// StatusCode is non-2XX status code
	StatusCode int
	// Body is at most HTTPStatusErrorBodyMaxLength
	Body string
}

HTTPStatusError is created from non-2XX HTTP response

func (*HTTPStatusError) Error

func (e *HTTPStatusError) Error() string

Error implements error. If e.Body is a marshalled string of httputil.ErrorJSON, Error returns ErrorJSON.Message . Otherwise Error returns a human-readable string that contains e.StatusCode and e.Body.

Jump to

Keyboard shortcuts

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