httpx

package
v0.1.16-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxErrorBodyBytes caps response bodies read on error paths.
	MaxErrorBodyBytes int64 = 2048
	// MaxJSONBodyBytes caps JSON response bodies decoded into structs.
	MaxJSONBodyBytes int64 = 1 << 20 // 1 MiB
	// MaxDownloadBodyBytes caps large download bodies read into memory.
	MaxDownloadBodyBytes int64 = 64 << 20 // 64 MiB
	// MaxGunzipOutputBytes caps decompressed bodies produced by streaming gunzip helpers.
	// This protects the CLI from gzip "zip bombs" while still allowing large patches.
	MaxGunzipOutputBytes int64 = 256 << 20 // 256 MiB
)

Variables

This section is empty.

Functions

func CheckStatus

func CheckStatus(resp *http.Response, expected int, action string) error

CheckStatus returns nil if resp.StatusCode matches expected. Otherwise it reads the error body and returns a formatted error.

func DecodeResponseJSON

func DecodeResponseJSON(r io.Reader, out any, limit int64) error

func DrainAndClose

func DrainAndClose(resp *http.Response)

DrainAndClose drains the response body to io.Discard and then closes it. Safe to call with a nil response or nil body.

func GunzipToBytes

func GunzipToBytes(r io.Reader, maxBytes int64) ([]byte, error)

GunzipToBytes reads a gzipped stream from r and returns the decompressed bytes. If maxBytes <= 0, MaxGunzipOutputBytes is used. An empty input stream returns an empty slice with no error.

func ReadErrorMessage

func ReadErrorMessage(r io.Reader, status string, limit int64) string

func RequireClientAndURL

func RequireClientAndURL(client *http.Client, base *url.URL) error

RequireClientAndURL validates that both an HTTP client and base URL are set.

func WrapError

func WrapError(prefix string, status string, r io.Reader) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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