client

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package client provides a high-level HTTP client with TLS fingerprint spoofing. It wraps the transport package with a convenient API for making HTTP requests that mimic real browser TLS fingerprints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a high-level HTTP client with TLS fingerprint spoofing.

func Chrome143Client

func Chrome143Client(opts ...Option) *Client

Chrome143Client creates a client configured for Chrome 143.

func Firefox146Client

func Firefox146Client(opts ...Option) *Client

Firefox146Client creates a client configured for Firefox 146.

func New

func New(opts ...Option) *Client

New creates a new Client with the given options.

func Safari261Client

func Safari261Client(opts ...Option) *Client

Safari261Client creates a client configured for Safari 26.1.

func (*Client) Close

func (c *Client) Close() error

Close releases all resources.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do executes a single HTTP request, following redirects if configured.

func (*Client) DoRequest

func (c *Client) DoRequest(ctx context.Context, req *transport.Request) (*transport.Response, error)

DoRequest executes a request using the transport's native Request type.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) (*http.Response, error)

Get performs a GET request.

func (*Client) Jar

func (c *Client) Jar() *cookie.Jar

Jar returns the client's cookie jar, or nil if cookies are disabled.

func (*Client) Post

func (c *Client) Post(ctx context.Context, url string, contentType string, body io.Reader) (*http.Response, error)

Post performs a POST request.

func (*Client) Profile

func (c *Client) Profile() *profile.BrowserProfile

Profile returns the client's browser profile.

func (*Client) Stats

func (c *Client) Stats() Stats

Stats returns current client statistics.

func (*Client) Transport

func (c *Client) Transport() *transport.Transport

Transport returns the underlying transport for advanced use.

type Config

type Config struct {
	Profile            *profile.BrowserProfile
	MaxConnsPerHost    int
	IdleTimeout        time.Duration
	Timeout            time.Duration
	Proxy              string        // Proxy address in "host:port:user:pass" or "host:port" format
	ProxyType          tls.ProxyType // HTTP or SOCKS5
	Jar                *cookie.Jar   // Cookie jar for automatic cookie management
	DNSCache           *dns.Cache    // Optional DNS cache for faster repeated lookups
	DisableCookies     bool          // When true, disables automatic cookie handling
	InsecureSkipVerify bool          // Skip TLS certificate verification (testing only)
	ForceHTTP1         bool          // Force HTTP/1.1 instead of HTTP/2 (higher throughput mode)
	EnableHTTP3        bool          // Enable HTTP/3 with auto-fallback to HTTP/2
	MaxRedirects       int           // Maximum redirects to follow (0=disabled, -1=unlimited, default=10)
	Logger             *log.Logger   // Optional logger for request/response logging
	HeaderOrder        []string      // Default HTTP header order (overrides browser profile)
	PseudoHeaderOrder  []string      // Default HTTP/2 pseudo-header order (overrides browser profile)
}

Config holds client configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for high-throughput use.

type Option

type Option func(*Config)

Option is a function that configures the client.

func WithCookieJar

func WithCookieJar(jar *cookie.Jar) Option

WithCookieJar sets a custom cookie jar. If not set, a new jar is created automatically.

func WithDNSCache

func WithDNSCache(ttl time.Duration) Option

WithDNSCache enables DNS caching with the specified TTL. This reduces DNS lookup latency for repeated requests to the same hosts. If ttl is 0, defaults to 5 minutes.

func WithHTTP1

func WithHTTP1() Option

WithHTTP1 forces the client to use HTTP/1.1 instead of HTTP/2. This can provide higher throughput by using multiple parallel connections, but offers less control over TLS fingerprinting (no HTTP/2 settings/priorities). Use this for high-throughput scenarios where fingerprint precision is less critical.

func WithHTTP3

func WithHTTP3() Option

WithHTTP3 enables HTTP/3 (QUIC) with auto-fallback to HTTP/2. HTTP/3 provides lower latency through 0-RTT connection establishment and multiplexing without head-of-line blocking. Falls back to HTTP/2 if QUIC fails. QUIC transport parameters are configured from the browser profile's HTTP3Profile.

func WithHTTPProxy

func WithHTTPProxy(proxy string) Option

WithHTTPProxy sets an HTTP CONNECT proxy. Format: "host:port" or "host:port:user:pass"

func WithHeaderOrder

func WithHeaderOrder(order []string) Option

WithHeaderOrder sets the default HTTP header order for all requests. This overrides the browser profile's header order. Headers should be specified in lowercase (e.g., "host", "user-agent", "accept").

func WithIdleTimeout

func WithIdleTimeout(d time.Duration) Option

WithIdleTimeout sets the idle connection timeout.

func WithInsecureSkipVerify

func WithInsecureSkipVerify() Option

WithInsecureSkipVerify skips TLS certificate verification. WARNING: This should only be used for testing purposes.

func WithLogger

func WithLogger(logger *log.Logger) Option

WithLogger sets a logger for request/response logging. Use log.Console() for pretty terminal output, log.File() for JSON file logging, or log.Multi() for both.

func WithMaxConnsPerHost

func WithMaxConnsPerHost(n int) Option

WithMaxConnsPerHost sets the maximum connections per host.

func WithMaxRedirects

func WithMaxRedirects(n int) Option

WithMaxRedirects sets the maximum number of redirects to follow. Set to 0 to disable redirect following, -1 for unlimited. Default is 10.

func WithNoCookies

func WithNoCookies() Option

WithNoCookies disables automatic cookie handling.

func WithNoRedirects

func WithNoRedirects() Option

WithNoRedirects disables automatic redirect following.

func WithProfile

func WithProfile(p *profile.BrowserProfile) Option

WithProfile sets the browser profile.

func WithPseudoHeaderOrder

func WithPseudoHeaderOrder(order []string) Option

WithPseudoHeaderOrder sets the HTTP/2 pseudo-header order for all requests. This overrides the browser profile's pseudo-header order. Example: []string{":method", ":authority", ":scheme", ":path"}

func WithSOCKS5Proxy

func WithSOCKS5Proxy(proxy string) Option

WithSOCKS5Proxy sets a SOCKS5 proxy. Format: "host:port" or "host:port:user:pass"

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the request timeout.

type Stats

type Stats struct {
	RequestCount  int64
	ErrorCount    int64
	BytesReceived int64
}

Stats returns client statistics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL