httpclient

package
v0.0.0-...-bcaad4a Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGenerationHTTPTimeout       = 10 * time.Minute
	DefaultRequestBytes          int64 = 32 * 1024 * 1024
	DefaultResponseBytes         int64 = 16 * 1024 * 1024
	DefaultErrorResponseBytes    int64 = 64 * 1024
)

Variables

This section is empty.

Functions

func CloneNoRedirects

func CloneNoRedirects(source *http.Client, timeout time.Duration) *http.Client

func CompleteJSONSSE

func CompleteJSONSSE[T any](
	ctx context.Context,
	config JSONSSEConfig,
	wireRequest any,
	operation string,
	read func(io.Reader, int64) (T, error),
	nonRetryableReadError func(error) bool,
) (T, error)

func DecodeBoundedJSON

func DecodeBoundedJSON(reader io.Reader, maximum int64, target any) (bool, error)

func FormatAPIError

func FormatAPIError(detail APIError) string

func FormatErrorMessage

func FormatErrorMessage(prefix string, maximum int64, format string, arguments ...any) string

func IsContextLimitAPIError

func IsContextLimitAPIError(detail APIError) bool

func IsObserverError

func IsObserverError(err error) bool

func IsPartialResponseError

func IsPartialResponseError(err error) bool

func IsRetryableAPIError

func IsRetryableAPIError(detail APIError) bool

func IsRetryableOperation

func IsRetryableOperation(err error) bool

func MarshalBoundedJSON

func MarshalBoundedJSON(value any, maximum int64) ([]byte, bool, error)

func NewJSONSSERequest

func NewJSONSSERequest(ctx context.Context, endpoint string, body []byte) (*http.Request, error)

func NewObserverError

func NewObserverError(operation string, cause error) error

func NewPartialResponseError

func NewPartialResponseError(cause error) error

func ParseRetryAfter

func ParseRetryAfter(value string, now time.Time) time.Duration

func ReadBounded

func ReadBounded(reader io.Reader, maximum int64) ([]byte, bool, error)

func ReadBoundedText

func ReadBoundedText(reader io.Reader, maximum int64) (string, bool, error)

func ReadHTTPStatusError

func ReadHTTPStatusError(response *http.Response, maximum int64) error

func ReadSSE

func ReadSSE(reader io.Reader, maximum int64, handle func([]byte) (bool, error)) (bool, error)

func RetryDelay

func RetryDelay(failedAttempts int, base, maximum time.Duration) time.Duration

func RetryDelayWithHint

func RetryDelayWithHint(failedAttempts int, base, maximum, hint time.Duration) time.Duration

func RetryableHTTPStatus

func RetryableHTTPStatus(status int) bool

func RetryableNetworkError

func RetryableNetworkError(err error) bool

func TruncateUTF8

func TruncateUTF8(text string, maximum int) string

Types

type APIError

type APIError struct {
	Type     string          `json:"type"`
	Code     APIErrorCode    `json:"code"`
	Message  string          `json:"message"`
	Metadata json.RawMessage `json:"metadata"`
}

type APIErrorCode

type APIErrorCode string

func (*APIErrorCode) UnmarshalJSON

func (code *APIErrorCode) UnmarshalJSON(data []byte) error

type APIErrorConfig

type APIErrorConfig struct {
	Prefix          string
	Maximum         int64
	ParseRetryAfter func(http.Header, time.Time) time.Duration
	FormatDetail    func(APIError) string
}

func (APIErrorConfig) Do

func (config APIErrorConfig) Do(ctx context.Context, client *http.Client, request *http.Request, operation string) (*http.Response, error)

func (APIErrorConfig) Errorf

func (config APIErrorConfig) Errorf(format string, arguments ...any) error

func (APIErrorConfig) RetryableWrapf

func (config APIErrorConfig) RetryableWrapf(cause error, format string, arguments ...any) error

func (APIErrorConfig) Wrapf

func (config APIErrorConfig) Wrapf(cause error, format string, arguments ...any) error

type APIResponseError

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

func (*APIResponseError) Detail

func (err *APIResponseError) Detail() APIError

func (*APIResponseError) Error

func (err *APIResponseError) Error() string

func (*APIResponseError) RetryAfter

func (err *APIResponseError) RetryAfter() time.Duration

func (*APIResponseError) StatusCode

func (err *APIResponseError) StatusCode() int

func (*APIResponseError) Unwrap

func (err *APIResponseError) Unwrap() error

type DeliveryTracker

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

func (*DeliveryTracker) Deliver

func (tracker *DeliveryTracker) Deliver(operation string, deliver func() error) error

func (*DeliveryTracker) Observed

func (tracker *DeliveryTracker) Observed() bool

func (*DeliveryTracker) WrapPartial

func (tracker *DeliveryTracker) WrapPartial(err error) error

type GenerationLimits

type GenerationLimits struct {
	RequestBytes  int64
	ResponseBytes int64
	ErrorBytes    int64
}

func (GenerationLimits) WithDefaults

func (limits GenerationLimits) WithDefaults() GenerationLimits

type JSONSSEConfig

type JSONSSEConfig struct {
	HTTPClient       *http.Client
	Endpoint         string
	ErrorConfig      APIErrorConfig
	PrepareRequest   func(context.Context, *http.Request) error
	MaxRequestBytes  int64
	MaxResponseBytes int64
}

type ObserverError

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

func (*ObserverError) Error

func (err *ObserverError) Error() string

func (*ObserverError) Unwrap

func (err *ObserverError) Unwrap() error

type PartialResponseError

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

func (*PartialResponseError) Error

func (err *PartialResponseError) Error() string

func (*PartialResponseError) Unwrap

func (err *PartialResponseError) Unwrap() error

type RetryPolicy

type RetryPolicy struct {
	MaximumAttempts int
	BaseDelay       time.Duration
	MaximumDelay    time.Duration
}

func (RetryPolicy) Next

func (policy RetryPolicy) Next(err error, failedAttempts int, retryable bool) (time.Duration, bool)

type TransportErrorDisposition

type TransportErrorDisposition struct {
	Cause          error
	ReturnDirectly bool
	Retryable      bool
}

func ClassifyTransportError

func ClassifyTransportError(ctx context.Context, err error) TransportErrorDisposition

Jump to

Keyboard shortcuts

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