Documentation
¶
Overview ¶
Package httpclient provides base-URL-scoped, context-owned outbound HTTP clients with bounded typed JSON helpers.
Index ¶
Constants ¶
const ( // DefaultTimeout bounds requests when a caller does not supply an HTTP // client. DefaultTimeout = 30 * time.Second // DefaultMaxResponseBodyBytes bounds typed response and remote error bodies. DefaultMaxResponseBodyBytes int64 = 4 << 20 // MaxResponseBodyBytes is the largest typed response bound accepted by New. // Larger payloads should use the raw streaming API. MaxResponseBodyBytes int64 = 64 << 20 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is one immutable base-URL-scoped outbound HTTP client.
func New ¶
New validates and copies an outbound client configuration. A nil HTTPClient selects a standard client with DefaultTimeout.
func (*Client) Do ¶
Do sends one raw request and returns a caller-owned response body. The request URL must remain within the configured base URL.
func (*Client) NewRequest ¶
func (client *Client) NewRequest( ctx context.Context, method string, reference string, body io.Reader, ) (*http.Request, error)
NewRequest creates a scoped request without sending it. Reference must be relative to the configured base path and contain no dot segments or fragment.
type JSONResponse ¶
JSONResponse is one successful typed outbound response.
type Options ¶
type Options struct {
BaseURL string
HTTPClient *http.Client
DefaultHeaders http.Header
UserAgent string
MaxResponseBodyBytes int64
DisallowUnknownResponseFields bool
}
Options configures one isolated outbound client.
type ResponseError ¶
type ResponseError struct {
Status int
// contains filtered or unexported fields
}
ResponseError reports a non-2xx remote response without retaining its raw body or rendering remote details in Error().
func (*ResponseError) Error ¶
func (responseErr *ResponseError) Error() string
Error returns stable status context without remote response detail.
func (*ResponseError) RemoteProblem ¶
func (responseErr *ResponseError) RemoteProblem() (web.Problem, bool)
RemoteProblem returns a validated copy of a remote RFC 9457 response.