Documentation
¶
Overview ¶
Package surf provides a comprehensive HTTP client library with advanced features for web scraping, automation, and HTTP/3 support with various browser fingerprinting capabilities.
Package surf provides HTTP/3 support with full uQUIC fingerprinting for advanced web scraping and automation. This file implements HTTP/3 transport with complete QUIC Initial Packet + TLS ClientHello fingerprinting, SOCKS5 proxy support, and automatic fallback to HTTP/2 for non-SOCKS5 proxies.
Index ¶
- type Body
- func (b *Body) Bytes() g.Bytes
- func (b *Body) Close() error
- func (b *Body) Contains(pattern any) bool
- func (b *Body) Dump(filename g.String) error
- func (b *Body) JSON(data any) error
- func (b *Body) Limit(limit int64) *Body
- func (b *Body) MD5() g.String
- func (b *Body) SSE(fn func(event *sse.Event) bool) error
- func (b *Body) Stream() *bufio.Reader
- func (b *Body) String() g.String
- func (b *Body) UTF8() g.String
- func (b *Body) XML(data any) error
- type Builder
- func (b *Builder) AddCookies(cookies ...*http.Cookie) *Builder
- func (b *Builder) AddHeaders(headers ...any) *Builder
- func (b *Builder) BasicAuth(authentication g.String) *Builder
- func (b *Builder) BearerAuth(authentication g.String) *Builder
- func (b *Builder) Boundary(boundary func() g.String) *Builder
- func (b *Builder) Build() *Client
- func (b *Builder) CacheBody() *Builder
- func (b *Builder) ContentType(contentType g.String) *Builder
- func (b *Builder) DNS(dns g.String) *Builder
- func (b *Builder) DNSOverTLS() *DNSOverTLS
- func (b *Builder) DisableCompression() *Builder
- func (b *Builder) DisableKeepAlive() *Builder
- func (b *Builder) FollowOnlyHostRedirects() *Builder
- func (b *Builder) ForceHTTP1() *Builder
- func (b *Builder) ForceHTTP2() *Builder
- func (b *Builder) ForwardHeadersOnRedirect() *Builder
- func (b *Builder) GetRemoteAddress() *Builder
- func (b *Builder) H2C() *Builder
- func (b *Builder) HTTP2Settings() *HTTP2Settings
- func (b *Builder) HTTP3() *Builder
- func (b *Builder) HTTP3Settings() *HTTP3Settings
- func (b *Builder) Impersonate() *Impersonate
- func (b *Builder) InterfaceAddr(address g.String) *Builder
- func (b *Builder) JA() *JA
- func (b *Builder) MaxRedirects(maxRedirects int) *Builder
- func (b *Builder) NotFollowRedirects() *Builder
- func (b *Builder) Proxy(proxy any) *Builder
- func (b *Builder) RedirectPolicy(fn func(*http.Request, []*http.Request) error) *Builder
- func (b *Builder) Retry(retryMax int, retryWait time.Duration, codes ...int) *Builder
- func (b *Builder) Session() *Builder
- func (b *Builder) SetDialer(dialer *net.Dialer) *Builder
- func (b *Builder) SetHeaders(headers ...any) *Builder
- func (b *Builder) Singleton() *Builder
- func (b Builder) String() string
- func (b *Builder) Timeout(timeout time.Duration) *Builder
- func (b *Builder) UnixSocket(address g.String) *Builder
- func (b *Builder) UserAgent(userAgent any) *Builder
- func (b *Builder) With(middleware any, priority ...int) *Builder
- func (b *Builder) WithContext(ctx context.Context) *Builder
- type Client
- func (c *Client) Builder() *Builder
- func (c *Client) CloseIdleConnections()
- func (c *Client) Delete(rawURL g.String, data ...any) *Request
- func (c *Client) FileUpload(rawURL, fieldName, filePath g.String, data ...any) *Request
- func (c *Client) Get(rawURL g.String, data ...any) *Request
- func (c *Client) GetClient() *http.Client
- func (c *Client) GetDialer() *net.Dialer
- func (c *Client) GetTLSConfig() *tls.Config
- func (c *Client) GetTransport() http.RoundTripper
- func (c *Client) Head(rawURL g.String) *Request
- func (c *Client) Multipart(rawURL g.String, multipartData g.MapOrd[g.String, g.String]) *Request
- func (c *Client) Patch(rawURL g.String, data any) *Request
- func (c *Client) Post(rawURL g.String, data any) *Request
- func (c *Client) Put(rawURL g.String, data any) *Request
- func (c *Client) Raw(raw, scheme g.String) *Request
- func (c *Client) Std() *_http.Client
- type CookieJarAdapter
- type Cookies
- type DNSOverTLS
- func (dot *DNSOverTLS) AdGuard() *Builder
- func (dot *DNSOverTLS) AddProvider(serverName g.String, addresses ...g.String) *Builder
- func (dot *DNSOverTLS) Ali() *Builder
- func (dot *DNSOverTLS) CIRAShield() *Builder
- func (dot *DNSOverTLS) Cloudflare() *Builder
- func (dot *DNSOverTLS) Forge() *Builder
- func (dot *DNSOverTLS) Google() *Builder
- func (dot *DNSOverTLS) LibreDNS() *Builder
- func (dot *DNSOverTLS) Quad101() *Builder
- func (dot *DNSOverTLS) Quad9() *Builder
- func (dot *DNSOverTLS) SB() *Builder
- func (dot *DNSOverTLS) Switch() *Builder
- type Debug
- type Err101ResponseCode
- type ErrUserAgentType
- type ErrWebSocketUpgrade
- type HTTP2Settings
- func (h *HTTP2Settings) ConnectionFlow(size uint32) *HTTP2Settings
- func (h *HTTP2Settings) EnablePush(size uint32) *HTTP2Settings
- func (h *HTTP2Settings) HeaderTableSize(size uint32) *HTTP2Settings
- func (h *HTTP2Settings) InitialWindowSize(size uint32) *HTTP2Settings
- func (h *HTTP2Settings) MaxConcurrentStreams(size uint32) *HTTP2Settings
- func (h *HTTP2Settings) MaxFrameSize(size uint32) *HTTP2Settings
- func (h *HTTP2Settings) MaxHeaderListSize(size uint32) *HTTP2Settings
- func (h *HTTP2Settings) PriorityFrames(priorityFrames []http2.PriorityFrame) *HTTP2Settings
- func (h *HTTP2Settings) PriorityParam(priorityParam http2.PriorityParam) *HTTP2Settings
- func (h *HTTP2Settings) Set() *Builder
- type HTTP3Settings
- type Headers
- type Impersonate
- func (im *Impersonate) Android() *Impersonate
- func (im *Impersonate) Chrome() *Builder
- func (im *Impersonate) FireFox() *Builder
- func (im *Impersonate) FireFoxPrivate() *Builder
- func (im *Impersonate) IOS() *Impersonate
- func (im *Impersonate) Linux() *Impersonate
- func (im *Impersonate) MacOS() *Impersonate
- func (im *Impersonate) RandomOS() *Impersonate
- func (im *Impersonate) Tor() *Builder
- func (im *Impersonate) TorPrivate() *Builder
- func (im *Impersonate) Windows() *Impersonate
- type ImpersonateOS
- type JA
- func (j *JA) Android() *Builder
- func (j *JA) Chrome() *Builder
- func (j *JA) Chrome100() *Builder
- func (j *JA) Chrome102() *Builder
- func (j *JA) Chrome106() *Builder
- func (j *JA) Chrome120() *Builder
- func (j *JA) Chrome120PQ() *Builder
- func (j *JA) Chrome142() *Builder
- func (j *JA) Chrome58() *Builder
- func (j *JA) Chrome62() *Builder
- func (j *JA) Chrome70() *Builder
- func (j *JA) Chrome72() *Builder
- func (j *JA) Chrome83() *Builder
- func (j *JA) Chrome87() *Builder
- func (j *JA) Chrome96() *Builder
- func (j *JA) Edge() *Builder
- func (j *JA) Edge106() *Builder
- func (j *JA) Edge85() *Builder
- func (j *JA) Firefox() *Builder
- func (j *JA) Firefox102() *Builder
- func (j *JA) Firefox105() *Builder
- func (j *JA) Firefox120() *Builder
- func (j *JA) Firefox141() *Builder
- func (j *JA) Firefox146() *Builder
- func (j *JA) Firefox55() *Builder
- func (j *JA) Firefox56() *Builder
- func (j *JA) Firefox63() *Builder
- func (j *JA) Firefox65() *Builder
- func (j *JA) Firefox99() *Builder
- func (j *JA) FirefoxPrivate146() *Builder
- func (j *JA) IOS() *Builder
- func (j *JA) IOS11() *Builder
- func (j *JA) IOS12() *Builder
- func (j *JA) IOS13() *Builder
- func (j *JA) IOS14() *Builder
- func (j *JA) Randomized() *Builder
- func (j *JA) RandomizedALPN() *Builder
- func (j *JA) RandomizedNoALPN() *Builder
- func (j *JA) Safari() *Builder
- func (j *JA) SetHelloID(id utls.ClientHelloID) *Builder
- func (j *JA) SetHelloSpec(spec utls.ClientHelloSpec) *Builder
- func (j *JA) Tor() *Builder
- func (j *JA) TorPrivate() *Builder
- type Request
- func (req *Request) AddCookies(cookies ...*http.Cookie) *Request
- func (req *Request) AddHeaders(headers ...any) *Request
- func (req *Request) Do() g.Result[*Response]
- func (req *Request) GetRequest() *http.Request
- func (req *Request) SetHeaders(headers ...any) *Request
- func (req *Request) WithContext(ctx context.Context) *Request
- type Response
- func (resp Response) Debug() *Debug
- func (resp Response) GetCookies(rawURL g.String) []*http.Cookie
- func (resp Response) GetResponse() *http.Response
- func (resp Response) Location() g.String
- func (resp Response) Referer() g.String
- func (resp Response) RemoteAddress() net.Addr
- func (resp *Response) SetCookies(rawURL g.String, cookies []*http.Cookie) error
- func (resp Response) TLSGrabber() *TLSData
- type StatusCode
- type TLSData
- type TransportAdapter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Body ¶
type Body struct {
Reader io.ReadCloser // ReadCloser for accessing the raw body content
// contains filtered or unexported fields
}
Body represents an HTTP response body with enhanced functionality and automatic caching. Provides convenient methods for parsing common data formats (JSON, XML, text) and includes features like automatic decompression, content caching, character set detection, and size limits.
func (*Body) Contains ¶
Contains checks if the body's content contains the provided pattern (byte slice, string, or *regexp.Regexp) and returns a boolean.
func (*Body) SSE ¶
SSE reads the body's content as Server-Sent Events (SSE) and calls the provided function for each event. It expects the function to take an *sse.Event pointer as its argument and return a boolean value. If the function returns false, the SSE reading stops.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides a fluent interface for configuring HTTP clients with various advanced features including proxy settings, TLS fingerprinting, HTTP/2 and HTTP/3 support, retry logic, redirect handling, and browser impersonation capabilities.
func (*Builder) AddCookies ¶
AddCookies adds cookies to the request.
func (*Builder) AddHeaders ¶
AddHeaders adds headers to the request, appending to any existing headers with the same name.
func (*Builder) BearerAuth ¶
BearerAuth sets the bearer token for the client.
func (*Builder) Build ¶
Build sets the provided settings for the client and returns the updated client. It configures various settings like HTTP2, sessions, keep-alive, dial TLS, resolver, interface address, timeout, and redirect policy.
func (*Builder) CacheBody ¶
CacheBody configures whether the client should cache the body of the response.
func (*Builder) ContentType ¶
ContentType sets the content type for the client.
func (*Builder) DNSOverTLS ¶
func (b *Builder) DNSOverTLS() *DNSOverTLS
DNSOverTLS configures the client to use DNS over TLS.
func (*Builder) DisableCompression ¶
DisableCompression disables compression for the HTTP client.
func (*Builder) DisableKeepAlive ¶
DisableKeepAlive disable keep-alive connections.
func (*Builder) FollowOnlyHostRedirects ¶
FollowOnlyHostRedirects configures whether the client should only follow redirects within the same host.
func (*Builder) ForceHTTP1 ¶
ForceHTTP1MW configures the client to use HTTP/1.1 forcefully.
func (*Builder) ForceHTTP2 ¶
ForceHTTP2MW configures the client to use HTTP/2 forcefully.
func (*Builder) ForwardHeadersOnRedirect ¶
ForwardHeadersOnRedirect adds a middleware to the ClientBuilder object that ensures HTTP headers are forwarded during a redirect.
func (*Builder) GetRemoteAddress ¶
GetRemoteAddress configures whether the client should get the remote address.
func (*Builder) HTTP2Settings ¶
func (b *Builder) HTTP2Settings() *HTTP2Settings
HTTP2Settings configures settings related to HTTP/2 and returns an http2s struct.
func (*Builder) HTTP3 ¶
HTTP3 enables HTTP/3 with automatic browser detection. Settings are applied lazily in Build() based on the impersonated browser. Usage: surf.NewClient().Builder().Impersonate().Chrome().HTTP3().Build()
func (*Builder) HTTP3Settings ¶
func (b *Builder) HTTP3Settings() *HTTP3Settings
HTTP3Settings configures settings related to HTTP/3 and returns an http3s struct.
func (*Builder) Impersonate ¶
func (b *Builder) Impersonate() *Impersonate
Impersonate configures something related to impersonation and returns an impersonate struct.
func (*Builder) InterfaceAddr ¶
InterfaceAddr sets the network interface address for the client.
func (*Builder) MaxRedirects ¶
MaxRedirects sets the maximum number of redirects the client should follow.
func (*Builder) NotFollowRedirects ¶
NotFollowRedirects disables following redirects for the client.
func (*Builder) Proxy ¶
Proxy sets the proxy settings for the client. Supports both static proxy configurations and dynamic proxy provider functions.
Static proxy examples:
.Proxy("socks5://127.0.0.1:9050")
.Proxy([]string{"socks5://proxy1", "http://proxy2"})
Dynamic proxy example:
.Proxy(func() g.String {
// Your proxy rotation logic here
return "socks5://127.0.0.1:9050"
})
func (*Builder) RedirectPolicy ¶
RedirectPolicy sets a custom redirect policy for the client.
func (*Builder) Retry ¶
Retry configures the retry behavior of the client.
Parameters:
retryMax: Maximum number of retries to be attempted.
retryWait: Duration to wait between retries.
codes: Optional list of HTTP status codes that trigger retries.
If no codes are provided, default codes will be used
(500, 429, 503 - Internal Server Error, Too Many Requests, Service Unavailable).
func (*Builder) SetHeaders ¶
SetHeaders sets headers for the request, replacing existing ones with the same name.
func (*Builder) Singleton ¶
Singleton configures the client to use a singleton instance, ensuring there's only one client instance. This is needed specifically for JA or Impersonate functionalities.
cli := surf.NewClient(). Builder(). Singleton(). // for reuse client Impersonate(). FireFox(). Build() defer cli.CloseIdleConnections()
func (*Builder) UnixSocket ¶
UnixSocket sets the path for a Unix domain socket. This allows the HTTP client to connect to the server using a Unix domain socket instead of a traditional TCP/IP connection.
func (*Builder) With ¶
With registers middleware into the client builder with optional priority.
It accepts one of the following middleware function types:
- func(*surf.Client) error — client middleware, modifies or initializes the client
- func(*surf.Request) error — request middleware, intercepts or transforms outgoing requests
- func(*surf.Response) error — response middleware, intercepts or transforms incoming responses
Parameters:
- middleware: A function matching one of the supported middleware types.
- priority (optional): Integer priority level. Lower values run earlier. Defaults to 0.
Middleware with the same priority are executed in order of insertion (FIFO). If the middleware type is not recognized, With panics with an informative error.
Example:
// Adding client middleware to modify client settings.
.With(func(client *surf.Client) error {
// Custom logic to modify the client settings.
return nil
})
// Adding request middleware to intercept outgoing requests.
.With(func(req *surf.Request) error {
// Custom logic to modify outgoing requests.
return nil
})
// Adding response middleware to intercept incoming responses.
.With(func(resp *surf.Response) error {
// Custom logic to handle incoming responses.
return nil
})
Note: Ensure that middleware functions adhere to the specified function signatures to work correctly with the With method.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a highly configurable HTTP client with middleware support, advanced transport options (HTTP/1.1, HTTP/2, HTTP/3), proxy handling, TLS fingerprinting, and comprehensive request/response processing capabilities.
func NewClient ¶
func NewClient() *Client
NewClient creates a new Client with sensible default settings including default dialer, TLS configuration, HTTP transport, and basic middleware.
func (*Client) Builder ¶
Builder returns a new Builder instance associated with this client. The builder allows for method chaining to configure various client options.
func (*Client) CloseIdleConnections ¶
func (c *Client) CloseIdleConnections()
CloseIdleConnections removes all entries from the cached transports. Specifically used when Singleton is enabled for JA3 or Impersonate functionalities.
func (*Client) Delete ¶
Delete creates a new HTTP DELETE request with the specified URL. Optional data parameter can be provided for request body.
func (*Client) FileUpload ¶
FileUpload creates a new multipart file upload request. It uploads a file from filePath using the specified fieldName in the form. Optional data can include additional form fields (g.MapOrd) or custom reader (io.Reader).
func (*Client) Get ¶
Get creates a new HTTP GET request with the specified URL. Optional data parameter can be provided for query parameters.
func (*Client) GetTLSConfig ¶
GetTLSConfig returns the tls.Config used by the Client.
func (*Client) GetTransport ¶
func (c *Client) GetTransport() http.RoundTripper
GetTransport returns the http.transport used by the Client.
func (*Client) Head ¶
Head creates a new HTTP HEAD request with the specified URL. HEAD requests are identical to GET but only return response headers.
func (*Client) Multipart ¶
Multipart creates a new multipart form data request with the specified form fields. The multipartData map contains field names and their corresponding values.
func (*Client) Patch ¶
Patch creates a new HTTP PATCH request with the specified URL and data. PATCH requests typically apply partial modifications to a resource.
func (*Client) Post ¶
Post creates a new HTTP POST request with the specified URL and data. Data can be of various types (string, map, struct) and will be encoded appropriately.
func (*Client) Put ¶
Put creates a new HTTP PUT request with the specified URL and data. PUT requests typically replace the entire resource at the specified URL.
func (*Client) Raw ¶
Raw creates a new HTTP request using the provided raw data and scheme. The raw parameter should contain the raw HTTP request data as a string. The scheme parameter specifies the scheme (e.g., http, https) for the request.
func (*Client) Std ¶
Std returns a standard net/http.Client that wraps the configured surf client. This is useful for integrating with third-party libraries that expect a standard net/http.Client while preserving most surf features.
Supported features:
- JA3/TLS fingerprinting
- HTTP/2 settings
- Cookies and sessions
- Request/Response middleware
- Headers (User-Agent, custom headers)
- Proxy configuration
- Timeout settings
- Redirect policies
- Impersonate browser headers
Known limitations:
- Retry logic is NOT supported (implemented in Request.Do(), not in transport)
- Response body caching is NOT supported
- Remote address tracking is NOT supported
- Request timing information is NOT available
For applications requiring retry logic, consider implementing it at the application level or use surf.Client directly for those specific requests.
Example usage:
surfClient := surf.NewClient().
Builder().
JA3().Chrome().
Session().
Build()
// For libraries expecting net/http.Client
stdClient := surfClient.Std()
botClient := &BaseBotClient{
Client: *stdClient,
}
type CookieJarAdapter ¶
type CookieJarAdapter struct {
// contains filtered or unexported fields
}
CookieJarAdapter adapts github.com/enetx/http.CookieJar to net/http.CookieJar. It provides bidirectional cookie conversion between the two HTTP packages, ensuring cookies set through either interface work correctly.
func (*CookieJarAdapter) Cookies ¶
func (c *CookieJarAdapter) Cookies(u *url.URL) []*_http.Cookie
Cookies implements http.CookieJar interface. It retrieves cookies from the underlying surf cookie jar and converts them to standard net/http cookie format.
func (*CookieJarAdapter) SetCookies ¶
func (c *CookieJarAdapter) SetCookies(u *url.URL, _cookies []*_http.Cookie)
SetCookies implements http.CookieJar interface. It converts standard net/http cookies to enetx/http format and delegates to the underlying surf cookie jar.
type Cookies ¶
Cookies represents a list of HTTP Cookies.
type DNSOverTLS ¶
type DNSOverTLS struct {
// contains filtered or unexported fields
}
DNSOverTLS is a configuration struct for DNS over TLS settings.
func (*DNSOverTLS) AdGuard ¶
func (dot *DNSOverTLS) AdGuard() *Builder
AdGuard sets up DNS over TLS with AdGuard DNS.
func (*DNSOverTLS) AddProvider ¶
AddProvider sets up DNS over TLS with a custom DNS provider. It configures a custom net.Resolver using the resolver method.
func (*DNSOverTLS) Ali ¶
func (dot *DNSOverTLS) Ali() *Builder
Ali sets up DNS over TLS with AliDNS.
func (*DNSOverTLS) CIRAShield ¶
func (dot *DNSOverTLS) CIRAShield() *Builder
CIRAShield sets up DNS over TLS with CIRA Canadian Shield DNS.
func (*DNSOverTLS) Cloudflare ¶
func (dot *DNSOverTLS) Cloudflare() *Builder
Cloudflare sets up DNS over TLS with Cloudflare DNS.
func (*DNSOverTLS) Forge ¶
func (dot *DNSOverTLS) Forge() *Builder
Forge sets up DNS over TLS with DNS Forge.
func (*DNSOverTLS) Google ¶
func (dot *DNSOverTLS) Google() *Builder
Google sets up DNS over TLS with Google Public DNS.
func (*DNSOverTLS) LibreDNS ¶
func (dot *DNSOverTLS) LibreDNS() *Builder
LibreDNS sets up DNS over TLS with LibreDNS.
func (*DNSOverTLS) Quad101 ¶
func (dot *DNSOverTLS) Quad101() *Builder
Quad101 sets up DNS over TLS with Quad101 DNS.
func (*DNSOverTLS) Quad9 ¶
func (dot *DNSOverTLS) Quad9() *Builder
Quad9 sets up DNS over TLS with Quad9 DNS.
func (*DNSOverTLS) SB ¶
func (dot *DNSOverTLS) SB() *Builder
SB sets up DNS over TLS with Secure DNS (dot.sb).
func (*DNSOverTLS) Switch ¶
func (dot *DNSOverTLS) Switch() *Builder
Switch sets up DNS over TLS with SWITCH DNS.
type Debug ¶
type Debug struct {
// contains filtered or unexported fields
}
Debug is a struct that holds debugging information for an HTTP response.
type Err101ResponseCode ¶
type Err101ResponseCode struct{ Msg string }
Err101ResponseCode indicates a 101 Switching Protocols response was received. This error is used to handle HTTP 101 responses that require protocol upgrades.
func (*Err101ResponseCode) Error ¶
func (e *Err101ResponseCode) Error() string
type ErrUserAgentType ¶
type ErrUserAgentType struct{ Msg string }
ErrUserAgentType indicates an invalid user agent type was provided. This error is returned when the user agent parameter is not of a supported type (string, g.String, slices, etc.).
func (*ErrUserAgentType) Error ¶
func (e *ErrUserAgentType) Error() string
type ErrWebSocketUpgrade ¶
type ErrWebSocketUpgrade struct{ Msg string }
ErrWebSocketUpgrade indicates that a request received a WebSocket upgrade response. This error is returned when the server responds with HTTP 101 Switching Protocols for WebSocket connections, which require special handling.
func (*ErrWebSocketUpgrade) Error ¶
func (e *ErrWebSocketUpgrade) Error() string
type HTTP2Settings ¶
type HTTP2Settings struct {
// contains filtered or unexported fields
}
HTTP2Settings represents HTTP/2 settings. https://lwthiker.com/networks/2022/06/17/http2-fingerprinting.html
func (*HTTP2Settings) ConnectionFlow ¶
func (h *HTTP2Settings) ConnectionFlow(size uint32) *HTTP2Settings
ConnectionFlow sets the flow control for the HTTP/2 connection.
func (*HTTP2Settings) EnablePush ¶
func (h *HTTP2Settings) EnablePush(size uint32) *HTTP2Settings
EnablePush enables HTTP/2 server push functionality.
func (*HTTP2Settings) HeaderTableSize ¶
func (h *HTTP2Settings) HeaderTableSize(size uint32) *HTTP2Settings
HeaderTableSize sets the header table size for HTTP/2 settings.
func (*HTTP2Settings) InitialWindowSize ¶
func (h *HTTP2Settings) InitialWindowSize(size uint32) *HTTP2Settings
InitialWindowSize sets the initial window size for HTTP/2 streams.
func (*HTTP2Settings) MaxConcurrentStreams ¶
func (h *HTTP2Settings) MaxConcurrentStreams(size uint32) *HTTP2Settings
MaxConcurrentStreams sets the maximum number of concurrent streams in HTTP/2.
func (*HTTP2Settings) MaxFrameSize ¶
func (h *HTTP2Settings) MaxFrameSize(size uint32) *HTTP2Settings
MaxFrameSize sets the maximum frame size for HTTP/2 frames.
func (*HTTP2Settings) MaxHeaderListSize ¶
func (h *HTTP2Settings) MaxHeaderListSize(size uint32) *HTTP2Settings
MaxHeaderListSize sets the maximum size of the header list in HTTP/2.
func (*HTTP2Settings) PriorityFrames ¶
func (h *HTTP2Settings) PriorityFrames(priorityFrames []http2.PriorityFrame) *HTTP2Settings
PriorityFrames sets the priority frames for HTTP/2.
func (*HTTP2Settings) PriorityParam ¶
func (h *HTTP2Settings) PriorityParam(priorityParam http2.PriorityParam) *HTTP2Settings
PriorityParam sets the priority parameter for HTTP/2.
func (*HTTP2Settings) Set ¶
func (h *HTTP2Settings) Set() *Builder
Set applies the accumulated HTTP/2 settings. It configures the HTTP/2 settings for the surf client.
type HTTP3Settings ¶
type HTTP3Settings struct {
// contains filtered or unexported fields
}
HTTP3Settings represents HTTP/3 settings with uQUIC fingerprinting support.
func (*HTTP3Settings) Chrome ¶
func (h *HTTP3Settings) Chrome() *HTTP3Settings
Chrome configures HTTP/3 settings to mimic Chrome browser.
func (*HTTP3Settings) Firefox ¶
func (h *HTTP3Settings) Firefox() *HTTP3Settings
Firefox configures HTTP/3 settings to mimic Firefox browser.
func (*HTTP3Settings) Set ¶
func (h *HTTP3Settings) Set() *Builder
Set applies the accumulated HTTP/3 settings. It configures the uQUIC transport for the surf client.
func (*HTTP3Settings) SetQUICID ¶
func (h *HTTP3Settings) SetQUICID(quicID uquic.QUICID) *HTTP3Settings
SetQUICID sets a custom QUIC ID for fingerprinting.
func (*HTTP3Settings) SetQUICSpec ¶
func (h *HTTP3Settings) SetQUICSpec(quicSpec uquic.QUICSpec) *HTTP3Settings
SetQUICSpec sets a custom QUIC spec for advanced fingerprinting.
type Headers ¶
Headers represents a collection of HTTP Headers.
func (Headers) Contains ¶
Contains checks if the header contains any of the specified patterns. It accepts a header name and a pattern (or list of patterns) and returns a boolean value indicating whether any of the patterns are found in the header values. The patterns can be a string, a slice of strings, or a slice of *regexp.Regexp.
type Impersonate ¶
type Impersonate struct {
// contains filtered or unexported fields
}
func (*Impersonate) Android ¶
func (im *Impersonate) Android() *Impersonate
Android sets the OS to Android.
func (*Impersonate) Chrome ¶
func (im *Impersonate) Chrome() *Builder
Chrome impersonates Chrome browser v142.
func (*Impersonate) FireFox ¶
func (im *Impersonate) FireFox() *Builder
FireFox impersonates Firefox browser v146.
func (*Impersonate) FireFoxPrivate ¶
func (im *Impersonate) FireFoxPrivate() *Builder
FireFoxPrivate impersonates Firefox private browser v146.
func (*Impersonate) RandomOS ¶
func (im *Impersonate) RandomOS() *Impersonate
RandomOS selects a random OS (Windows, macOS, Linux, Android, or iOS) for the impersonate.
func (*Impersonate) Tor ¶
func (im *Impersonate) Tor() *Builder
Tor impersonates Tor browser v14.5.6.
func (*Impersonate) TorPrivate ¶
func (im *Impersonate) TorPrivate() *Builder
TorPrivate impersonates Tor private browser v14.5.6.
func (*Impersonate) Windows ¶
func (im *Impersonate) Windows() *Impersonate
Windows sets the OS to Windows.
type ImpersonateOS ¶
type ImpersonateOS int
ImpersonateOS defines the operating system to impersonate in User-Agent strings.
type JA ¶
type JA struct {
// contains filtered or unexported fields
}
JA provides JA3/4 TLS fingerprinting capabilities for HTTP clients. JA is a method for creating SSL/TLS client fingerprints to identify and classify malware or other applications. This struct allows configuring various TLS ClientHello specifications to mimic different browsers and applications for advanced HTTP client behavior.
Reference: https://lwthiker.com/networks/2022/06/17/tls-fingerprinting.html
func (*JA) Chrome ¶
Chrome sets the JA3/4 fingerprint to mimic the latest Chrome browser (auto-detection).
func (*JA) Chrome106 ¶
Chrome106 sets the JA3/4 fingerprint to mimic Chrome version 106 with shuffled extensions.
func (*JA) Chrome120PQ ¶
Chrome120PQ sets the JA3/4 fingerprint to mimic Chrome version 120 with post-quantum cryptography support.
func (*JA) Firefox ¶
Firefox sets the JA3/4 fingerprint to mimic the latest Firefox browser (auto-detection).
func (*JA) Firefox102 ¶
Firefox102 sets the JA3/4 fingerprint to mimic Firefox version 102.
func (*JA) Firefox105 ¶
Firefox105 sets the JA3/4 fingerprint to mimic Firefox version 105.
func (*JA) Firefox120 ¶
Firefox120 sets the JA3/4 fingerprint to mimic Firefox version 120.
func (*JA) Firefox141 ¶
Firefox141 sets the JA3/4 fingerprint to mimic Firefox version 141.
func (*JA) Firefox146 ¶
Firefox146 sets the JA3/4 fingerprint to mimic Firefox version 146.
func (*JA) FirefoxPrivate146 ¶
FirefoxPrivate146 sets the JA3/4 fingerprint to mimic Firefox private version 146.
func (*JA) IOS ¶
IOS sets the JA3/4 fingerprint to mimic the latest iOS Safari browser (auto-detection).
func (*JA) Randomized ¶
Randomized sets a completely randomized JA3/4 fingerprint.
func (*JA) RandomizedALPN ¶
RandomizedALPN sets a randomized JA3/4 fingerprint with ALPN (Application-Layer Protocol Negotiation).
func (*JA) RandomizedNoALPN ¶
RandomizedNoALPN sets a randomized JA3/4 fingerprint without ALPN.
func (*JA) Safari ¶
Safari sets the JA3/4 fingerprint to mimic the latest Safari browser (auto-detection).
func (*JA) SetHelloID ¶
func (j *JA) SetHelloID(id utls.ClientHelloID) *Builder
SetHelloID sets a ClientHelloID for the TLS connection.
The provided ClientHelloID is used to customize the TLS handshake. This should be a valid identifier that can be mapped to a specific ClientHelloSpec.
It returns a pointer to the Options struct for method chaining. This allows additional configuration methods to be called on the result.
Example usage:
JA().SetHelloID(utls.HelloChrome_Auto)
func (*JA) SetHelloSpec ¶
func (j *JA) SetHelloSpec(spec utls.ClientHelloSpec) *Builder
SetHelloSpec sets a custom ClientHelloSpec for the TLS connection.
This method allows you to set a custom ClientHelloSpec to be used during the TLS handshake. The provided spec should be a valid ClientHelloSpec.
It returns a pointer to the Options struct for method chaining. This allows additional configuration methods to be called on the result.
Example usage:
JA().SetHelloSpec(spec)
func (*JA) TorPrivate ¶
TorPrivate sets the JA3/4 fingerprint to mimic Tor Browser private version 14.5.6.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request represents an HTTP request with additional surf-specific functionality. It wraps the standard http.Request and provides enhanced features like middleware support, retry capabilities, remote address tracking, and structured error handling.
func (*Request) AddCookies ¶
AddCookies adds one or more HTTP cookies to the request. Cookies are added to the request headers and will be sent with the HTTP request. Returns the request for method chaining.
func (*Request) AddHeaders ¶
AddHeaders adds HTTP headers to the request, appending to any existing headers with the same name. Unlike SetHeaders, this method preserves existing headers and adds new values. Supports the same input formats as SetHeaders. Returns the request for method chaining.
func (*Request) Do ¶
Do executes the HTTP request and returns a Response wrapped in a Result type. This is the main method that performs the actual HTTP request with full surf functionality: - Applies request middleware (authentication, headers, tracing, etc.) - Preserves request body for potential retries - Implements retry logic with configurable status codes and delays - Measures request timing for performance analysis - Handles request preparation errors and write errors
func (*Request) GetRequest ¶
GetRequest returns the underlying standard http.Request. Provides access to the wrapped HTTP request for advanced use cases.
func (*Request) SetHeaders ¶
SetHeaders sets HTTP headers for the request, replacing any existing headers with the same name. Supports multiple input formats: - Two arguments: key, value (string or g.String) - Single argument: http.Header, Headers, map types, or g.Map types Maintains header order for fingerprinting purposes when using g.MapOrd. Returns the request for method chaining.
func (*Request) WithContext ¶
WithContext associates a context with the request for cancellation and deadlines. The context can be used to cancel the request, set timeouts, or pass request-scoped values. Returns the request for method chaining. If ctx is nil, the request is unchanged.
type Response ¶
type Response struct {
*Client // Embedded client provides access to all client functionality
URL *url.URL // Final URL after following redirects
Body *Body // Enhanced response body with compression support and caching
Headers Headers // Response headers with convenience methods
UserAgent g.String // User agent that was used for the request
Proto g.String // HTTP protocol version (HTTP/1.1, HTTP/2, HTTP/3)
Cookies Cookies // Response cookies with enhanced functionality
Time time.Duration // Total request duration including retries
ContentLength int64 // Content-Length header value (-1 if not specified)
StatusCode StatusCode // HTTP status code with convenience methods
Attempts int // Number of retry attempts made for this request
// contains filtered or unexported fields
}
Response represents an HTTP response with enhanced functionality and metadata. It wraps the standard http.Response and provides additional features like timing information, retry attempts tracking, enhanced cookie management, and convenient access methods.
func (Response) GetCookies ¶
GetCookies returns all cookies from the response that would be sent to the specified URL. Filters cookies based on domain, path, and security attributes.
func (Response) GetResponse ¶
GetResponse returns the underlying standard http.Response. Provides access to the wrapped HTTP response for advanced use cases.
func (Response) Location ¶
Location returns the HTTP Location header value, typically used in redirects. Contains the URL that the client should redirect to for 3xx status codes.
func (Response) Referer ¶
Referer returns the HTTP Referer header value from the original request. This indicates which page linked to the resource being requested.
func (Response) RemoteAddress ¶
RemoteAddress returns the network address of the server that sent this response. Useful for logging, debugging, or connection analysis.
func (*Response) SetCookies ¶
SetCookies stores cookies in the client's cookie jar for the specified URL. This allows the cookies to be automatically sent with future requests to matching URLs.
func (Response) TLSGrabber ¶
TLSGrabber extracts TLS connection information from the response. Returns detailed TLS connection data including certificates, cipher suites, and protocol version if the response was received over a TLS connection. Returns nil for non-TLS connections.
type StatusCode ¶
type StatusCode int
StatusCode represents an HTTP status code with convenient classification methods. Extends the basic integer status code with methods to easily identify the response category.
func (StatusCode) IsClientError ¶
func (s StatusCode) IsClientError() bool
IsClientError returns true if the status code indicates a client error [400, 500].
func (StatusCode) IsInformational ¶
func (s StatusCode) IsInformational() bool
IsInformational returns true if the status code is in the informational range [100, 200].
func (StatusCode) IsRedirection ¶
func (s StatusCode) IsRedirection() bool
IsRedirection returns true if the status code indicates a redirection [300, 400].
func (StatusCode) IsServerError ¶
func (s StatusCode) IsServerError() bool
IsServerError returns true if the status code indicates a server error [500, ∞].
func (StatusCode) IsSuccess ¶
func (s StatusCode) IsSuccess() bool
IsSuccess returns true if the status code indicates a successful response [200, 300].
func (StatusCode) Text ¶
func (s StatusCode) Text() string
Text returns the textual representation of the status code.
type TLSData ¶
type TLSData struct {
ExtensionServerName string // Server name extension of the TLS certificate.
FingerprintSHA256 string // SHA-256 fingerprint of the certificate.
FingerprintSHA256OpenSSL string // SHA-256 fingerprint compatible with OpenSSL.
TLSVersion string // TLS version used.
CommonName []string // List of common names associated with the certificate.
DNSNames []string // List of DNS names associated with the certificate.
Emails []string // List of email addresses associated with the certificate.
IssuerCommonName []string // List of common names of the certificate issuer.
IssuerOrg []string // List of organizations of the certificate issuer.
Organization []string // List of organizations associated with the certificate.
}
TLSData represents information about a TLS certificate.
type TransportAdapter ¶
type TransportAdapter struct {
// contains filtered or unexported fields
}
TransportAdapter adapts surf.Client to net/http.RoundTripper It uses the full surf pipeline including middleware
func (*TransportAdapter) CloseIdleConnections ¶
func (s *TransportAdapter) CloseIdleConnections()
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
std
command
|
|
|
internal
|
|
|
specclone
Package specclone provides deep cloning functionality for uTLS ClientHelloSpec structures.
|
Package specclone provides deep cloning functionality for uTLS ClientHelloSpec structures. |
|
pkg
|
|
|
quicconn
Package quicconn provides a net.PacketConn adapter for feeding QUIC stacks (such as quic-go) with datagrams originating from a generic net.Conn.
|
Package quicconn provides a net.PacketConn adapter for feeding QUIC stacks (such as quic-go) with datagrams originating from a generic net.Conn. |
|
profiles
|
|