Documentation
ΒΆ
Overview ΒΆ
Package httpcloak provides an HTTP client with perfect browser TLS/HTTP fingerprinting.
httpcloak allows you to make HTTP requests that are indistinguishable from real browsers, bypassing TLS fingerprinting, HTTP/2 fingerprinting, and header-based bot detection.
Basic usage:
client := httpcloak.New("chrome-131")
defer client.Close()
resp, err := client.Get(ctx, "https://example.com")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(resp.Body))
With options:
client := httpcloak.New("chrome-131",
httpcloak.WithTimeout(30*time.Second),
httpcloak.WithProxy("http://user:pass@proxy:8080"),
)
Index ΒΆ
- func Presets() []string
- type Client
- func (c *Client) Close()
- func (c *Client) Do(ctx context.Context, req *Request) (*Response, error)
- func (c *Client) Get(ctx context.Context, url string) (*Response, error)
- func (c *Client) GetWithHeaders(ctx context.Context, url string, headers map[string][]string) (*Response, error)
- func (c *Client) Post(ctx context.Context, url string, body io.Reader, contentType string) (*Response, error)
- func (c *Client) PostForm(ctx context.Context, url string, body []byte) (*Response, error)
- func (c *Client) PostJSON(ctx context.Context, url string, body []byte) (*Response, error)
- type Option
- type RedirectInfo
- type Request
- type Response
- type Session
- func (s *Session) Close()
- func (s *Session) Do(ctx context.Context, req *Request) (*Response, error)
- func (s *Session) DoStream(ctx context.Context, req *Request) (*StreamResponse, error)
- func (s *Session) DoWithBody(ctx context.Context, req *Request, bodyReader io.Reader) (*Response, error)
- func (s *Session) Get(ctx context.Context, url string) (*Response, error)
- func (s *Session) GetCookies() map[string]string
- func (s *Session) GetStream(ctx context.Context, url string) (*StreamResponse, error)
- func (s *Session) GetStreamWithHeaders(ctx context.Context, url string, headers map[string][]string) (*StreamResponse, error)
- func (s *Session) Marshal() ([]byte, error)
- func (s *Session) Save(path string) error
- func (s *Session) SetCookie(name, value string)
- type SessionOption
- func WithConnectTo(requestHost, connectHost string) SessionOption
- func WithECHFrom(domain string) SessionOption
- func WithForceHTTP1() SessionOption
- func WithForceHTTP2() SessionOption
- func WithForceHTTP3() SessionOption
- func WithInsecureSkipVerify() SessionOption
- func WithRedirects(follow bool, maxRedirects int) SessionOption
- func WithRetry(count int) SessionOption
- func WithRetryConfig(count int, waitMin, waitMax time.Duration, retryOnStatus []int) SessionOption
- func WithSessionPreferIPv4() SessionOption
- func WithSessionProxy(proxyURL string) SessionOption
- func WithSessionTCPProxy(proxyURL string) SessionOption
- func WithSessionTimeout(d time.Duration) SessionOption
- func WithSessionUDPProxy(proxyURL string) SessionOption
- func WithoutRedirects() SessionOption
- func WithoutRetry() SessionOption
- type StreamResponse
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
Types ΒΆ
type Client ΒΆ
type Client struct {
// contains filtered or unexported fields
}
Client is an HTTP client with browser fingerprint spoofing
func New ΒΆ
New creates a new HTTP client with the specified browser fingerprint.
Available presets:
- "chrome-131" (recommended)
- "chrome-131-windows"
- "chrome-131-macos"
- "chrome-133"
- "chrome-133-windows"
Example:
client := httpcloak.New("chrome-131")
defer client.Close()
func (*Client) GetWithHeaders ΒΆ
func (c *Client) GetWithHeaders(ctx context.Context, url string, headers map[string][]string) (*Response, error)
GetWithHeaders performs a GET request with custom headers
func (*Client) Post ΒΆ
func (c *Client) Post(ctx context.Context, url string, body io.Reader, contentType string) (*Response, error)
Post performs a POST request
type RedirectInfo ΒΆ added in v1.5.1
type RedirectInfo struct {
StatusCode int
URL string
Headers map[string][]string // Multi-value headers
}
RedirectInfo contains information about a redirect response
type Request ΒΆ
type Request struct {
Method string
URL string
Headers map[string][]string // Multi-value headers (matches http.Header)
Body io.Reader // Streaming body for uploads
Timeout time.Duration
}
Request represents an HTTP request
type Response ΒΆ
type Response struct {
StatusCode int
Headers map[string][]string // Multi-value headers (matches http.Header)
Body io.ReadCloser // Streaming body - call Close() when done
FinalURL string
Protocol string
History []*RedirectInfo
// contains filtered or unexported fields
}
Response represents an HTTP response
func (*Response) Bytes ΒΆ added in v1.5.3
Bytes reads and returns the entire response body. The body can only be read once unless cached.
func (*Response) GetHeader ΒΆ added in v1.5.3
GetHeader returns the first value for the given header key.
func (*Response) GetHeaders ΒΆ added in v1.5.3
GetHeaders returns all values for the given header key.
type Session ΒΆ
type Session struct {
// contains filtered or unexported fields
}
Session represents a persistent HTTP session with cookie management
func LoadSession ΒΆ added in v1.5.5
LoadSession loads a session from a file
func NewSession ΒΆ
func NewSession(preset string, opts ...SessionOption) *Session
NewSession creates a new persistent session with cookie management
func UnmarshalSession ΒΆ added in v1.5.5
UnmarshalSession loads a session from JSON bytes
func (*Session) DoStream ΒΆ added in v1.5.3
DoStream executes an HTTP request and returns a streaming response The caller is responsible for closing the response when done Note: Streaming does NOT support redirects - use Do() for redirect handling
func (*Session) DoWithBody ΒΆ added in v1.5.3
func (s *Session) DoWithBody(ctx context.Context, req *Request, bodyReader io.Reader) (*Response, error)
DoWithBody executes a request with an io.Reader as the body for streaming uploads
func (*Session) GetCookies ΒΆ
GetCookies returns all cookies stored in the session
func (*Session) GetStreamWithHeaders ΒΆ added in v1.5.3
func (s *Session) GetStreamWithHeaders(ctx context.Context, url string, headers map[string][]string) (*StreamResponse, error)
GetStreamWithHeaders performs a streaming GET request with custom headers
type SessionOption ΒΆ
type SessionOption func(*sessionConfig)
SessionOption configures a session
func WithConnectTo ΒΆ added in v1.5.2
func WithConnectTo(requestHost, connectHost string) SessionOption
WithConnectTo sets a host mapping for domain fronting. Requests to requestHost will connect to connectHost instead. The TLS SNI and Host header will still use requestHost.
func WithECHFrom ΒΆ added in v1.5.2
func WithECHFrom(domain string) SessionOption
WithECHFrom sets a domain to fetch ECH config from. Instead of fetching ECH from the target domain's DNS, the config will be fetched from this domain. Useful for Cloudflare domains - use "cloudflare-ech.com" to get ECH config that works for any Cloudflare-proxied domain.
func WithForceHTTP1 ΒΆ added in v1.0.1
func WithForceHTTP1() SessionOption
WithForceHTTP1 forces HTTP/1.1 protocol
func WithForceHTTP2 ΒΆ added in v1.0.1
func WithForceHTTP2() SessionOption
WithForceHTTP2 forces HTTP/2 protocol
func WithForceHTTP3 ΒΆ added in v1.1.1
func WithForceHTTP3() SessionOption
WithForceHTTP3 forces HTTP/3 protocol (QUIC)
func WithInsecureSkipVerify ΒΆ added in v1.0.1
func WithInsecureSkipVerify() SessionOption
WithInsecureSkipVerify disables SSL certificate verification
func WithRedirects ΒΆ added in v1.0.1
func WithRedirects(follow bool, maxRedirects int) SessionOption
WithRedirects configures redirect behavior
func WithRetry ΒΆ added in v1.0.1
func WithRetry(count int) SessionOption
WithRetry enables retry with default settings
func WithRetryConfig ΒΆ added in v1.0.1
func WithRetryConfig(count int, waitMin, waitMax time.Duration, retryOnStatus []int) SessionOption
WithRetryConfig configures retry behavior
func WithSessionPreferIPv4 ΒΆ added in v1.1.2
func WithSessionPreferIPv4() SessionOption
WithSessionPreferIPv4 makes the session prefer IPv4 addresses over IPv6. Use this on networks with poor IPv6 connectivity.
func WithSessionProxy ΒΆ
func WithSessionProxy(proxyURL string) SessionOption
WithSessionProxy sets a proxy for the session
func WithSessionTCPProxy ΒΆ added in v1.5.3
func WithSessionTCPProxy(proxyURL string) SessionOption
WithSessionTCPProxy sets a proxy for TCP-based protocols (HTTP/1.1 and HTTP/2). Use this with WithSessionUDPProxy for split proxy configuration.
func WithSessionTimeout ΒΆ
func WithSessionTimeout(d time.Duration) SessionOption
WithSessionTimeout sets the timeout for session requests
func WithSessionUDPProxy ΒΆ added in v1.5.3
func WithSessionUDPProxy(proxyURL string) SessionOption
WithSessionUDPProxy sets a proxy for UDP-based protocols (HTTP/3 via MASQUE). Use this with WithSessionTCPProxy for split proxy configuration.
func WithoutRedirects ΒΆ added in v1.0.1
func WithoutRedirects() SessionOption
WithoutRedirects disables automatic redirect following
func WithoutRetry ΒΆ added in v1.0.5
func WithoutRetry() SessionOption
WithoutRetry explicitly disables retry
type StreamResponse ΒΆ added in v1.5.3
type StreamResponse struct {
StatusCode int
Headers map[string][]string
FinalURL string
Protocol string
ContentLength int64 // -1 if unknown (chunked encoding)
// contains filtered or unexported fields
}
StreamResponse represents a streaming HTTP response where the body is read incrementally. Use this for large file downloads.
func (*StreamResponse) Close ΒΆ added in v1.5.3
func (r *StreamResponse) Close() error
Close closes the response body - must be called when done
func (*StreamResponse) Read ΒΆ added in v1.5.3
func (r *StreamResponse) Read(p []byte) (n int, err error)
Read reads data from the response body
func (*StreamResponse) ReadAll ΒΆ added in v1.5.3
func (r *StreamResponse) ReadAll() ([]byte, error)
ReadAll reads the entire response body into memory This defeats the purpose of streaming but is useful for small responses
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
Package client provides an HTTP client with browser TLS/HTTP fingerprint spoofing.
|
Package client provides an HTTP client with browser TLS/HTTP fingerprint spoofing. |
|
examples
|
|
|
go-examples/basic
command
Example: Basic HTTP requests with httpcloak
|
Example: Basic HTTP requests with httpcloak |
|
go-examples/cloudflare
command
Example: Multiple requests to Cloudflare trace endpoint
|
Example: Multiple requests to Cloudflare trace endpoint |
|
go-examples/high-performance
command
Example: High-Performance Downloads
|
Example: High-Performance Downloads |
|
go-examples/session
command
Example: Session management with cookies
|
Example: Session management with cookies |
|
go-examples/session-resumption
command
Example: Session Resumption (0-RTT)
|
Example: Session Resumption (0-RTT) |
|
go-examples/streaming
command
Example: Streaming Downloads with httpcloak
|
Example: Streaming Downloads with httpcloak |
|
Package protocol defines the IPC message types for communication between the httpcloak daemon and language SDKs (Python, Node.js, etc.)
|
Package protocol defines the IPC message types for communication between the httpcloak daemon and language SDKs (Python, Node.js, etc.) |