Documentation
¶
Index ¶
- func ReadBody(body io.ReadCloser, maxBodyBytes int64) (bodyStr string, truncated bool, err error)
- func RedactError(err error) error
- type Client
- func (c *Client) Delete(ctx context.Context, url string, headers map[string]string, maxBodyBytes int64) (*Response, error)
- func (c *Client) Do(ctx context.Context, method, url string, headers map[string]string, ...) (*Response, error)
- func (c *Client) Get(ctx context.Context, url string, headers map[string]string, maxBodyBytes int64) (*Response, error)
- func (c *Client) Post(ctx context.Context, url string, headers map[string]string, body string, ...) (*Response, error)
- func (c *Client) Put(ctx context.Context, url string, headers map[string]string, body string, ...) (*Response, error)
- type HTTPDoer
- type Option
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadBody ¶
ReadBody reads an HTTP response body with optional size limiting. If maxBodyBytes <= 0, reads the entire body without limit (existing notify behavior). If maxBodyBytes > 0, limits reading to maxBodyBytes and sets truncated=true if exceeded. Uses io.LimitReader to detect truncation by reading maxBodyBytes+1. Tolerates EOF and ErrUnexpectedEOF errors per existing responseToString pattern. Returns the body string and truncation status, or an error on read failure.
func RedactError ¶ added in v0.11.7
RedactError hides untrusted transport diagnostics (URLs, credentials and response payloads), while preserving the cause for errors.Is and errors.As.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps HTTP operations with an optional caller-selected timeout and convenience methods.
func NewClient ¶
NewClient creates a new HTTP client with options. By default, total request lifetime is controlled by the caller's context. TCP connection establishment is bounded to 30 seconds and TLS negotiation to 10 seconds. These setup limits do not bound response headers or body reading.
func (*Client) Delete ¶
func (c *Client) Delete(ctx context.Context, url string, headers map[string]string, maxBodyBytes int64) (*Response, error)
Delete is a convenience method for DELETE requests.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method, url string, headers map[string]string, body string, maxBodyBytes int64) (*Response, error)
Do executes an HTTP request with the given parameters. Creates a request with context, applies any explicit client timeout, applies headers, executes via doer, reads response via ReadBody. Returns Response or error.
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, url string, headers map[string]string, maxBodyBytes int64) (*Response, error)
Get is a convenience method for GET requests.
type HTTPDoer ¶
HTTPDoer abstracts HTTP request execution for testing. *http.Client satisfies this interface natively.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithDoerDecorator ¶ added in v0.11.7
WithDoerDecorator wraps the constructed transport without replacing its timeout policy. The decorator is useful for request instrumentation and must preserve cancellation.
func WithTimeout ¶
WithTimeout sets a request timeout when timeout is positive. A shorter parent context deadline remains authoritative through normal context composition.
type Response ¶
Response represents an HTTP response with parsed components. StatusCode is the HTTP status code (e.g., 200, 404, 503). Body is the response body as a string. Headers maps canonicalized header names to their values (multi-value headers joined with ", "). Truncated indicates whether the response body was truncated due to size limits.