{"modulePath":"github.com/Method-Security/pkg","version":"v0.2.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpclient\n\n## Variables\n\n```go\nvar ErrResponseBodyTooLarge = errors.New(\"HTTP response body exceeds configured limit\")\n```\nErrResponseBodyTooLarge indicates that a configured response body limit was exceeded.\n\n## Functions\n\n```go\nfunc DelayWithJitter(baseDelay, jitter time.Duration) time.Duration\n```\nDelayWithJitter returns a duration with random jitter applied. The result is between baseDelay and baseDelay + jitter.\n\n```go\nfunc Sleep(baseDelay, jitter time.Duration)\n```\nSleep pauses execution for the base delay plus random jitter.\n\n## Types\n\n```go\ntype Client struct {\n\t// contains filtered or unexported fields\n}\n```\nClient wraps http.Client with Method-specific defaults and helpers.\n\n```go\nfunc New(opts ...Option) *Client\n```\nNew creates a new HTTP client with the given options.\n\n```go\nfunc (c *Client) CloseIdleConnections()\n```\nCloseIdleConnections closes this client's idle connections without interrupting active requests. The transport supplied to WithTransport is not affected.\n\n```go\nfunc (c *Client) Do(req *http.Request) (*Response, error)\n```\nDo executes an HTTP request, handling redirects manually.\n\n```go\nfunc (c *Client) Get(ctx context.Context, url string) (*Response, error)\n```\nGet performs an HTTP GET request.\n\n```go\nfunc (c *Client) GetJSON(ctx context.Context, url string, dest any) (*Response, error)\n```\nGetJSON performs a GET request and unmarshals the JSON response into dest.\n\n```go\nfunc (c *Client) GetWithHeaders(ctx context.Context, url string, headers map[string]string) (*Response, error)\n```\nGetWithHeaders performs an HTTP GET request with custom headers.\n\n```go\nfunc (c *Client) Head(ctx context.Context, url string) (*Response, error)\n```\nHead performs an HTTP HEAD request.\n\n```go\nfunc (c *Client) HeadWithHeaders(ctx context.Context, url string, headers map[string]string) (*Response, error)\n```\nHeadWithHeaders performs an HTTP HEAD request with custom headers.\n\n```go\nfunc (c *Client) IsAlive(ctx context.Context, url string) bool\n```\nIsAlive checks if a URL responds with a non-404/502 status code.\n\n```go\nfunc (c *Client) Post(ctx context.Context, url string, body any) (*Response, error)\n```\nPost performs an HTTP POST request with a JSON body.\n\n```go\nfunc (c *Client) PostForm(ctx context.Context, requestURL string, values url.Values) (*Response, error)\n```\nPostForm performs an HTTP POST request with form-encoded body.\n\n```go\nfunc (c *Client) PostFormWithHeaders(ctx context.Context, requestURL string, values url.Values, headers map[string]string) (*Response, error)\n```\nPostFormWithHeaders performs an HTTP POST request with form-encoded body and custom headers.\n\n```go\nfunc (c *Client) PostJSON(ctx context.Context, url string, body any, dest any) (*Response, error)\n```\nPostJSON performs a POST request with a JSON body and unmarshals the response into dest.\n\n```go\nfunc (c *Client) PostWithHeaders(ctx context.Context, url string, body any, headers map[string]string) (*Response, error)\n```\nPostWithHeaders performs an HTTP POST request with a JSON body and custom headers.\n\n```go\nfunc (c *Client) Request(ctx context.Context, method, requestURL string, body io.Reader, headers map[string]string) (*Response, error)\n```\nRequest performs an HTTP request with an arbitrary method, body, and headers.\n\n```go\ntype Option func(*Options)\n```\nOption is a functional option for configuring the HTTP client.\n\n```go\nfunc WithBlockCrossDomainRedirects() Option\n```\nWithBlockCrossDomainRedirects blocks redirects that change the host.\n\n```go\nfunc WithDefaultHeaders(headers map[string]string) Option\n```\nWithDefaultHeaders sets headers that are applied to every request.\n\n```go\nfunc WithHTTPProxy(proxyURL string) Option\n```\nWithHTTPProxy sets an HTTP/HTTPS proxy URL for all requests. The proxyURL should be in the format: [http://\\[user:pass@]host:port](http://[user:pass@]host:port)\n\n```go\nfunc WithMaxRedirects(n int) Option\n```\nWithMaxRedirects sets the maximum number of redirects to follow. Set to 0 to disable redirects. Default is 10.\n\n```go\nfunc WithMaxResponseBodyBytes(n int64) Option\n```\nWithMaxResponseBodyBytes limits buffered response bodies. Non-positive values retain the default unlimited buffering. Oversized responses return the bounded body and ErrResponseBodyTooLarge.\n\n```go\nfunc WithRedirectTracking() Option\n```\nWithRedirectTracking enables tracking of the full redirect chain in responses.\n\n```go\nfunc WithSOCKSProxy(proxyURL string) Option\n```\nWithSOCKSProxy sets a SOCKS5 proxy URL for all requests. The proxyURL should be in the format: socks5://\\[user:pass@]host:port\n\n```go\nfunc WithTLSVerify(verify bool) Option\n```\nWithTLSVerify controls certificate verification for the default transport. WithTransport takes precedence over this option.\n\n```go\nfunc WithTimeout(d time.Duration) Option\n```\nWithTimeout sets the HTTP request timeout.\n\n```go\nfunc WithTransport(transport *http.Transport) Option\n```\nWithTransport supplies a transport to clone for this client's exclusive use. Its dialing, TLS, HTTP/2, and connection settings replace the defaults, including WithTLSVerify. Explicit proxy options still apply; SOCKS replaces DialContext. A nil transport selects the default transport. Do not mutate the supplied transport's configuration while New is cloning it.\n\n```go\ntype Options struct {\n\tTimeout                   time.Duration\n\tVerifyTLS                 bool\n\tMaxRedirects              int\n\tTrackRedirects            bool\n\tBlockCrossDomainRedirects bool\n\tDefaultHeaders            map[string]string\n\tHTTPProxy                 string\n\tSOCKSProxy                string\n\tTransport                 *http.Transport\n\tMaxResponseBodyBytes      int64\n}\n```\nOptions configures the HTTP client behavior.\n\n```go\ntype RedirectHop struct {\n\tURL        string\n\tStatusCode int\n}\n```\nRedirectHop records a single redirect in the chain.\n\n```go\ntype Response struct {\n\tStatusCode    int\n\tHeaders       http.Header\n\tBody          []byte\n\tRedirectChain []RedirectHop\n}\n```\nResponse wraps an HTTP response with additional metadata.\n\n","path":"github.com/Method-Security/pkg/httpclient","name":"httpclient","synopsis":"","isRedistributable":true}
