Documentation
¶
Overview ¶
Package client provides an HTTP/2 client with TLS and HTTP/2 fingerprinting. It reuses the same frame, hpack, flowcontrol, and stream packages as the server.
Index ¶
- Variables
- type Client
- func (c *Client) Close() error
- func (c *Client) Do(req *Request) (*Response, error)
- func (c *Client) DoBatch(reqs []*Request) ([]*Response, error)
- func (c *Client) Get(rawURL string) (*Response, error)
- func (c *Client) Head(rawURL string) (*Response, error)
- func (c *Client) Post(rawURL, contentType string, body []byte) (*Response, error)
- func (c *Client) SetInsecureSkipVerify(v bool) *Client
- func (c *Client) SetProxy(proxyURL string) error
- func (c *Client) SetProxyWithAuth(proxyURL, user, pass string) error
- func (c *Client) SetSOCKS5Proxy(addr, user, pass string) error
- type ClientConn
- type ConnPool
- type CookieJar
- type Header
- type PoolOption
- type Request
- type Response
- type RetryConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrConnClosed = errors.New("client: connection closed") ErrGoAway = errors.New("client: server sent GOAWAY") ErrStreamReset = errors.New("client: stream reset by server") ErrNotH2 = errors.New("client: server did not negotiate h2") )
Errors returned by ClientConn.
var ErrPoolClosed = errors.New("client: connection pool closed")
ErrPoolClosed is returned when an operation is attempted on a closed pool.
var ErrProxyConnect = errors.New("client: proxy connection failed")
ErrProxyConnect is returned when a proxy CONNECT or SOCKS5 connection fails.
var ErrTooManyRedirects = errors.New("client: too many redirects")
ErrTooManyRedirects is returned when the redirect limit is exceeded.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
UserAgent string
FollowRedirects bool
MaxRedirects int
CookieJar *CookieJar
RetryConfig *RetryConfig
RequestTimeout time.Duration
// contains filtered or unexported fields
}
Client is the high-level HTTP/2 client with browser fingerprinting, cookie jar, redirect following, retry with backoff, and proxy support.
func NewChromeClient ¶
func NewChromeClient() *Client
NewChromeClient creates a client mimicking Chrome's TLS and HTTP/2 fingerprint.
func NewFirefoxClient ¶
func NewFirefoxClient() *Client
NewFirefoxClient creates a client mimicking Firefox's TLS and HTTP/2 fingerprint.
func NewRandomClient ¶
func NewRandomClient() *Client
NewRandomClient creates a client with a randomized TLS fingerprint.
func NewSafariClient ¶
func NewSafariClient() *Client
NewSafariClient creates a client mimicking Safari's TLS fingerprint (uses Chrome H2 profile since Safari doesn't have a distinct one).
func (*Client) Do ¶
Do sends a Request and returns a Response. It handles cookie injection, redirect following, and retry.
func (*Client) DoBatch ¶
DoBatch sends multiple requests concurrently and returns responses in order. Returns on the first error encountered.
func (*Client) SetInsecureSkipVerify ¶
SetInsecureSkipVerify disables TLS certificate verification. Testing only.
func (*Client) SetProxyWithAuth ¶
SetProxyWithAuth configures an HTTP CONNECT proxy with credentials.
func (*Client) SetSOCKS5Proxy ¶
SetSOCKS5Proxy configures a SOCKS5 proxy.
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
ClientConn is a single HTTP/2 client connection.
func Dial ¶
func Dial(addr string, tlsDialer *blazetls.TLSDialer, profile *h2fingerprint.H2Profile) (*ClientConn, error)
Dial establishes an HTTP/2 connection to addr (host:port) using the given TLS dialer and HTTP/2 fingerprint profile.
func (*ClientConn) ActiveStreams ¶
func (cc *ClientConn) ActiveStreams() int
ActiveStreams returns the number of active streams.
func (*ClientConn) Close ¶
func (cc *ClientConn) Close() error
Close gracefully closes the connection.
func (*ClientConn) GoingAway ¶
func (cc *ClientConn) GoingAway() bool
GoingAway reports whether the server has sent GOAWAY.
func (*ClientConn) IsClosed ¶
func (cc *ClientConn) IsClosed() bool
IsClosed reports whether the connection is closed.
func (*ClientConn) PeerSettings ¶
func (cc *ClientConn) PeerSettings() peerSettings
PeerSettings returns the server's current settings.
func (*ClientConn) Ping ¶
func (cc *ClientConn) Ping()
Ping sends a PING frame and does not wait for the response.
type ConnPool ¶
type ConnPool struct {
// contains filtered or unexported fields
}
ConnPool manages a pool of HTTP/2 connections with transparent multiplexing. It auto-scales connections when existing ones are saturated, detects dead connections, and handles GOAWAY gracefully.
func NewConnPool ¶
func NewConnPool(dialer *blazetls.TLSDialer, profile *h2fingerprint.H2Profile, opts ...PoolOption) *ConnPool
NewConnPool creates a new connection pool.
type CookieJar ¶
type CookieJar struct {
// contains filtered or unexported fields
}
CookieJar is a thread-safe cookie jar with domain and path matching.
type PoolOption ¶
type PoolOption func(*ConnPool)
PoolOption configures a ConnPool.
func WithDialTimeout ¶
func WithDialTimeout(d time.Duration) PoolOption
WithDialTimeout sets the timeout for establishing new connections.
func WithHealthCheckInterval ¶
func WithHealthCheckInterval(d time.Duration) PoolOption
WithHealthCheckInterval sets the interval between health checks. Set to 0 to disable health checks.
func WithMaxConnsPerHost ¶
func WithMaxConnsPerHost(n int) PoolOption
WithMaxConnsPerHost sets the maximum number of connections per host.
func WithMaxIdlePerHost ¶
func WithMaxIdlePerHost(n int) PoolOption
WithMaxIdlePerHost sets the maximum number of idle connections to keep per host.
func WithWaitTimeout ¶
func WithWaitTimeout(d time.Duration) PoolOption
WithWaitTimeout sets the maximum time to wait for an available connection when all connections are saturated and the max connections limit is reached.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is a high-level HTTP request builder.
func NewRequest ¶
NewRequest creates a new Request with the given method and URL.
func (*Request) SetHeaderOrder ¶
SetHeaderOrder reorders the headers slice to match the given order. Headers not in the order list are appended after.
type Response ¶
Response is a high-level HTTP response.
type RetryConfig ¶
type RetryConfig struct {
MaxRetries int
InitialDelay time.Duration
MaxDelay time.Duration
Multiplier float64
Jitter float64
RetryOn []int // status codes to retry on
RetryOnError bool // retry on connection errors
}
RetryConfig configures retry behavior with exponential backoff.
func DefaultRetryConfig ¶
func DefaultRetryConfig() *RetryConfig
DefaultRetryConfig returns sensible retry defaults.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package h2fingerprint defines HTTP/2 connection fingerprint profiles.
|
Package h2fingerprint defines HTTP/2 connection fingerprint profiles. |
|
Package tls provides TLS fingerprinting for the BlazeHTTP client.
|
Package tls provides TLS fingerprinting for the BlazeHTTP client. |