Documentation
¶
Index ¶
- func RandomString() string
- func SanitizeCookieName(n string) string
- func SanitizeCookieValue(v string, quoted bool) string
- type BasicAuth
- type ClientOption
- func WithBaseURL(baseURL string) ClientOption
- func WithCookieJar(jar http.CookieJar) ClientOption
- func WithFollowRedirects(followRedirects bool, maxRedirects int) ClientOption
- func WithProxy(proxy string) ClientOption
- func WithTLSClientConfig(config *tls.Config) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
- func WithTransport(transport http.RoundTripper) ClientOption
- type HTTPClient
- func (c *HTTPClient) Close() error
- func (c *HTTPClient) Delete(url string, options *Options) (*Response, error)
- func (c *HTTPClient) Get(url string, options *Options) (*Response, error)
- func (c *HTTPClient) Head(url string, options *Options) (*Response, error)
- func (c *HTTPClient) Options(url string, options *Options) (*Response, error)
- func (c *HTTPClient) Patch(url string, options *Options) (*Response, error)
- func (c *HTTPClient) Post(url string, options *Options) (*Response, error)
- func (c *HTTPClient) Put(url string, options *Options) (*Response, error)
- func (c *HTTPClient) Request(ctx context.Context, method, targetURL string, options *Options) (*Response, error)
- type Multipart
- type Options
- type Response
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RandomString ¶
func RandomString() string
RandomString generates a pseudo-random alphanumeric string based on the current Unix timestamp in nanoseconds and a random uint64 value, both encoded in base36. It guarantees a safe [string] construction without slice panic risks.
func SanitizeCookieName ¶
SanitizeCookieName cleans up a cookie name by replacing newline (\n) and carriage return (\r) characters with hyphens. It returns the sanitized [string].
func SanitizeCookieValue ¶
SanitizeCookieValue validates and cleans a cookie value based on allowed bytes. If the value contains spaces or commas, or if the quoted [bool] parameter is true, the resulting [string] will be wrapped in double quotes.
Types ¶
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption defines the configuration function type for request options.
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL sets the default base URL for the client.
func WithCookieJar ¶
func WithCookieJar(jar http.CookieJar) ClientOption
WithCookieJar sets the cookie jar implementation.
func WithFollowRedirects ¶
func WithFollowRedirects(followRedirects bool, maxRedirects int) ClientOption
WithFollowRedirects configures redirect behavior.
func WithTLSClientConfig ¶
func WithTLSClientConfig(config *tls.Config) ClientOption
WithTLSClientConfig sets SSL/TLS client options.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets the timeout duration for requests.
func WithTransport ¶
func WithTransport(transport http.RoundTripper) ClientOption
WithTransport sets a custom http.RoundTripper.
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient represents the HTTP client wrapper around the standard net/http client.
func NewHTTPClient ¶
func NewHTTPClient(options ...ClientOption) *HTTPClient
NewHTTPClient instantiates a new HTTP client based strictly on standard library implementations.
func (*HTTPClient) Close ¶
func (c *HTTPClient) Close() error
Close closes idle connections on the underlying transport.
func (*HTTPClient) Delete ¶
func (c *HTTPClient) Delete(url string, options *Options) (*Response, error)
Delete sends a DELETE request.
func (*HTTPClient) Get ¶
func (c *HTTPClient) Get(url string, options *Options) (*Response, error)
Get sends a GET request.
func (*HTTPClient) Head ¶
func (c *HTTPClient) Head(url string, options *Options) (*Response, error)
Head sends a HEAD request.
func (*HTTPClient) Options ¶
func (c *HTTPClient) Options(url string, options *Options) (*Response, error)
Options sends an OPTIONS request.
func (*HTTPClient) Patch ¶
func (c *HTTPClient) Patch(url string, options *Options) (*Response, error)
Patch sends a PATCH request.
func (*HTTPClient) Post ¶
func (c *HTTPClient) Post(url string, options *Options) (*Response, error)
Post sends a POST request.
type Options ¶
type Options struct {
Headers http.Header
BasicAuth *BasicAuth
BearerToken string
Cookies []*http.Cookie
Query url.Values
Body any
JSON any
Form map[string]string
Multipart map[string]*Multipart
}
Options contains parameters applied to an individual request.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport implements an HTTP transport that supports standard HTTP/HTTPS configurations and custom Alt-Svc tracking features using standard libraries.
func NewTransport ¶
NewTransport creates a new Transport instance.