Documentation
¶
Index ¶
- Constants
- func CheckStatus(resp *http.Response, expected int, action string) error
- func DecodeResponseJSON(r io.Reader, out any, limit int64) error
- func DrainAndClose(resp *http.Response)
- func GunzipToBytes(r io.Reader, maxBytes int64) ([]byte, error)
- func ReadErrorMessage(r io.Reader, status string, limit int64) string
- func RequireClientAndURL(client *http.Client, base *url.URL) error
- func WrapError(prefix string, status string, r io.Reader) error
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 ¶
CheckStatus returns nil if resp.StatusCode matches expected. Otherwise it reads the error body and returns a formatted error.
func DrainAndClose ¶
DrainAndClose drains the response body to io.Discard and then closes it. Safe to call with a nil response or nil body.
func GunzipToBytes ¶
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 RequireClientAndURL ¶
RequireClientAndURL validates that both an HTTP client and base URL are set.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.