httputil

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const MaxErrorBodyLen = 200

MaxErrorBodyLen is the maximum length of an error body snippet.

View Source
const MaxResponseBody = 1 << 20

MaxResponseBody is the upper bound on HTTP response body reads (1 MiB).

Variables

This section is empty.

Functions

func NewClient

func NewClient(timeout time.Duration, version string) *http.Client

NewClient creates an HTTP client with the given timeout and a default User-Agent. The version string is included in the User-Agent header.

func ReadBody

func ReadBody(r io.Reader) ([]byte, error)

ReadBody reads up to MaxResponseBody bytes from r. Returns an error if the body exceeds MaxResponseBody.

func TruncateBody

func TruncateBody(b []byte, max int) string

TruncateBody returns up to max bytes of b as a string.

Types

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer abstracts HTTP client operations for testability.

Jump to

Keyboard shortcuts

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