Documentation
¶
Index ¶
- func ReadBody(body io.ReadCloser, maxBodyBytes int64) (bodyStr string, truncated bool, err 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.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps HTTP operations with configurable timeout and convenience methods.
func NewClient ¶
NewClient creates a new HTTP client with options. Default: *http.Client with 30s timeout.
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 timeout when no deadline exists, 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 WithTimeout ¶
WithTimeout sets the default timeout for requests.
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.