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.
Index ¶
- Constants
- 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() g.Result[*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) ForceHTTP3() *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 g.String) *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) SetHeaders(headers ...any) *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) Close() error
- 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) InitialStreamID(id 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) NoRFC7540Priorities(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
- func (h *HTTP3Settings) EnableConnectProtocol(num uint64) *HTTP3Settings
- func (h *HTTP3Settings) EnableWebtransport(num uint64) *HTTP3Settings
- func (h *HTTP3Settings) Grease() *HTTP3Settings
- func (h *HTTP3Settings) H3Datagram(num uint64) *HTTP3Settings
- func (h *HTTP3Settings) MaxFieldSectionSize(num uint64) *HTTP3Settings
- func (h *HTTP3Settings) QpackBlockedStreams(num uint64) *HTTP3Settings
- func (h *HTTP3Settings) QpackMaxTableCapacity(num uint64) *HTTP3Settings
- func (h *HTTP3Settings) Set() *Builder
- func (h *HTTP3Settings) SettingsH3Datagram(num uint64) *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) 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) Chrome144() *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) Firefox147() *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) FirefoxPrivate147() *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
- 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 ¶
const ( SETTINGS_QPACK_MAX_TABLE_CAPACITY = 0x01 SETTINGS_MAX_FIELD_SECTION_SIZE = 0x06 SETTINGS_QPACK_BLOCKED_STREAMS = 0x07 SETTINGS_ENABLE_CONNECT_PROTOCOL = 0x08 SETTINGS_H3_DATAGRAM = 0x33 H3_DATAGRAM = 0xFFD277 SETTINGS_ENABLE_WEBTRANSPORT = 0x2B603742 )
HTTP/3 SETTINGS frame parameter identifiers as defined in RFC 9114.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Body ¶ added in v1.0.51
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 ¶ added in v1.0.51
Contains checks if the body's content contains the provided pattern (byte slice, string, or *regexp.Regexp) and returns a boolean.
func (*Body) Dump ¶ added in v1.0.51
Dump dumps the body's content to a file with the given filename.
func (*Body) JSON ¶ added in v1.0.51
JSON decodes the body's content as JSON into the provided data structure.
func (*Body) Limit ¶ added in v1.0.51
Limit sets the body's size limit and returns the modified body.
func (*Body) SSE ¶ added in v1.0.53
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.
func (*Body) Stream ¶ added in v1.0.51
Stream returns the body's bufio.Reader for streaming the content.
type Builder ¶ added in v1.0.100
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 ¶ added in v1.0.100
AddCookies adds cookies to the request.
func (*Builder) AddHeaders ¶ added in v1.0.100
AddHeaders adds headers to the request, appending to any existing headers with the same name.
func (*Builder) BasicAuth ¶ added in v1.0.100
BasicAuth sets the basic authentication credentials for the client.
func (*Builder) BearerAuth ¶ added in v1.0.100
BearerAuth sets the bearer token for the client.
func (*Builder) Build ¶ added in v1.0.100
Build applies all configured settings and returns the client. Returns g.Result with error if any middleware fails.
func (*Builder) CacheBody ¶ added in v1.0.100
CacheBody configures whether the client should cache the body of the response.
func (*Builder) ContentType ¶ added in v1.0.100
ContentType sets the content type for the client.
func (*Builder) DNSOverTLS ¶ added in v1.0.100
func (b *Builder) DNSOverTLS() *DNSOverTLS
DNSOverTLS configures the client to use DNS over TLS.
func (*Builder) DisableCompression ¶ added in v1.0.100
DisableCompression disables automatic response body decompression.
func (*Builder) DisableKeepAlive ¶ added in v1.0.100
DisableKeepAlive disable keep-alive connections.
func (*Builder) FollowOnlyHostRedirects ¶ added in v1.0.100
FollowOnlyHostRedirects configures whether the client should only follow redirects within the same host.
func (*Builder) ForceHTTP1 ¶ added in v1.0.100
ForceHTTP1 configures the client to use HTTP/1.1 forcefully.
func (*Builder) ForceHTTP2 ¶ added in v1.0.147
ForceHTTP2 configures the client to use HTTP/2 forcefully.
func (*Builder) ForceHTTP3 ¶ added in v1.0.154
ForceHTTP3 configures the client to use HTTP/2 forcefully.
func (*Builder) ForwardHeadersOnRedirect ¶ added in v1.0.100
ForwardHeadersOnRedirect adds a middleware to the ClientBuilder object that ensures HTTP headers are forwarded during a redirect.
func (*Builder) GetRemoteAddress ¶ added in v1.0.100
GetRemoteAddress configures whether the client should get the remote address.
func (*Builder) HTTP2Settings ¶ added in v1.0.100
func (b *Builder) HTTP2Settings() *HTTP2Settings
HTTP2Settings configures settings related to HTTP/2 and returns an http2s struct.
func (*Builder) HTTP3Settings ¶ added in v1.0.101
func (b *Builder) HTTP3Settings() *HTTP3Settings
HTTP3Settings configures settings related to HTTP/3 and returns an http3s struct.
func (*Builder) Impersonate ¶ added in v1.0.100
func (b *Builder) Impersonate() *Impersonate
Impersonate configures something related to impersonation and returns an impersonate struct.
func (*Builder) InterfaceAddr ¶ added in v1.0.100
InterfaceAddr sets the local network interface for outbound connections. Accepts either an IP address (e.g., "192.168.1.100", "::1") or an interface name (e.g., "eth0", "en0").
func (*Builder) MaxRedirects ¶ added in v1.0.100
MaxRedirects sets the maximum number of redirects the client should follow.
func (*Builder) NotFollowRedirects ¶ added in v1.0.100
NotFollowRedirects disables following redirects for the client.
func (*Builder) RedirectPolicy ¶ added in v1.0.100
RedirectPolicy sets a custom redirect policy for the client.
func (*Builder) Retry ¶ added in v1.0.100
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) Session ¶ added in v1.0.100
Session configures whether the client should maintain a session.
func (*Builder) SetHeaders ¶ added in v1.0.100
SetHeaders sets headers for the request, replacing existing ones with the same name.
func (Builder) String ¶ added in v1.0.100
String generate a string representation of the ClientBuilder instance.
func (*Builder) UnixSocket ¶ added in v1.0.137
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 ¶ added in v1.0.100
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 ¶ added in v1.0.50
Builder returns a new Builder instance associated with this client. The builder allows for method chaining to configure various client options.
func (*Client) Close ¶ added in v1.0.170
Close completely shuts down the client and releases all resources. After calling Close, the client should not be used.
func (*Client) CloseIdleConnections ¶
func (c *Client) CloseIdleConnections()
CloseIdleConnections closes idle connections while keeping the client usable. Safe to call periodically to free resources during long-running operations.
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 ¶ added in v1.0.100
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 ¶ added in v1.0.100
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 ¶ added in v1.0.100
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 ¶ added in v1.0.100
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 ¶ added in v1.0.51
Cookies represents a list of HTTP Cookies.
type DNSOverTLS ¶ added in v1.0.100
type DNSOverTLS struct {
// contains filtered or unexported fields
}
DNSOverTLS is a configuration struct for DNS over TLS settings.
func (*DNSOverTLS) AdGuard ¶ added in v1.0.100
func (dot *DNSOverTLS) AdGuard() *Builder
AdGuard sets up DNS over TLS with AdGuard DNS.
func (*DNSOverTLS) AddProvider ¶ added in v1.0.100
AddProvider sets up DNS over TLS with a custom DNS provider. It configures a custom net.Resolver using the resolver method.
func (*DNSOverTLS) Ali ¶ added in v1.0.100
func (dot *DNSOverTLS) Ali() *Builder
Ali sets up DNS over TLS with AliDNS.
func (*DNSOverTLS) CIRAShield ¶ added in v1.0.100
func (dot *DNSOverTLS) CIRAShield() *Builder
CIRAShield sets up DNS over TLS with CIRA Canadian Shield DNS.
func (*DNSOverTLS) Cloudflare ¶ added in v1.0.100
func (dot *DNSOverTLS) Cloudflare() *Builder
Cloudflare sets up DNS over TLS with Cloudflare DNS.
func (*DNSOverTLS) Forge ¶ added in v1.0.100
func (dot *DNSOverTLS) Forge() *Builder
Forge sets up DNS over TLS with DNS Forge.
func (*DNSOverTLS) Google ¶ added in v1.0.100
func (dot *DNSOverTLS) Google() *Builder
Google sets up DNS over TLS with Google Public DNS.
func (*DNSOverTLS) LibreDNS ¶ added in v1.0.100
func (dot *DNSOverTLS) LibreDNS() *Builder
LibreDNS sets up DNS over TLS with LibreDNS.
func (*DNSOverTLS) Quad101 ¶ added in v1.0.100
func (dot *DNSOverTLS) Quad101() *Builder
Quad101 sets up DNS over TLS with Quad101 DNS.
func (*DNSOverTLS) Quad9 ¶ added in v1.0.100
func (dot *DNSOverTLS) Quad9() *Builder
Quad9 sets up DNS over TLS with Quad9 DNS.
func (*DNSOverTLS) SB ¶ added in v1.0.100
func (dot *DNSOverTLS) SB() *Builder
SB sets up DNS over TLS with Secure DNS (dot.sb).
func (*DNSOverTLS) Switch ¶ added in v1.0.100
func (dot *DNSOverTLS) Switch() *Builder
Switch sets up DNS over TLS with SWITCH DNS.
type Debug ¶ added in v1.0.100
type Debug struct {
// contains filtered or unexported fields
}
Debug is a struct that holds debugging information for an HTTP response.
type Err101ResponseCode ¶ added in v1.0.100
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 ¶ added in v1.0.100
func (e *Err101ResponseCode) Error() string
type ErrUserAgentType ¶ added in v1.0.100
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 ¶ added in v1.0.100
func (e *ErrUserAgentType) Error() string
type ErrWebSocketUpgrade ¶ added in v1.0.100
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 ¶ added in v1.0.100
func (e *ErrWebSocketUpgrade) Error() string
type HTTP2Settings ¶ added in v1.0.100
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 ¶ added in v1.0.100
func (h *HTTP2Settings) ConnectionFlow(size uint32) *HTTP2Settings
ConnectionFlow sets the flow control for the HTTP/2 connection.
func (*HTTP2Settings) EnablePush ¶ added in v1.0.100
func (h *HTTP2Settings) EnablePush(size uint32) *HTTP2Settings
EnablePush enables HTTP/2 server push functionality.
func (*HTTP2Settings) HeaderTableSize ¶ added in v1.0.100
func (h *HTTP2Settings) HeaderTableSize(size uint32) *HTTP2Settings
HeaderTableSize sets the header table size for HTTP/2 settings.
func (*HTTP2Settings) InitialStreamID ¶ added in v1.0.150
func (h *HTTP2Settings) InitialStreamID(id uint32) *HTTP2Settings
InitialStreamID sets the initial stream id for HTTP/2 streams.
func (*HTTP2Settings) InitialWindowSize ¶ added in v1.0.100
func (h *HTTP2Settings) InitialWindowSize(size uint32) *HTTP2Settings
InitialWindowSize sets the initial window size for HTTP/2 streams.
func (*HTTP2Settings) MaxConcurrentStreams ¶ added in v1.0.100
func (h *HTTP2Settings) MaxConcurrentStreams(size uint32) *HTTP2Settings
MaxConcurrentStreams sets the maximum number of concurrent streams in HTTP/2.
func (*HTTP2Settings) MaxFrameSize ¶ added in v1.0.100
func (h *HTTP2Settings) MaxFrameSize(size uint32) *HTTP2Settings
MaxFrameSize sets the maximum frame size for HTTP/2 frames.
func (*HTTP2Settings) MaxHeaderListSize ¶ added in v1.0.100
func (h *HTTP2Settings) MaxHeaderListSize(size uint32) *HTTP2Settings
MaxHeaderListSize sets the maximum size of the header list in HTTP/2.
func (*HTTP2Settings) NoRFC7540Priorities ¶ added in v1.0.166
func (h *HTTP2Settings) NoRFC7540Priorities(size uint32) *HTTP2Settings
NoRFC7540Priorities disables RFC 7540 priority signaling in HTTP/2.
func (*HTTP2Settings) PriorityFrames ¶ added in v1.0.100
func (h *HTTP2Settings) PriorityFrames(priorityFrames []http2.PriorityFrame) *HTTP2Settings
PriorityFrames sets the priority frames for HTTP/2.
func (*HTTP2Settings) PriorityParam ¶ added in v1.0.100
func (h *HTTP2Settings) PriorityParam(priorityParam http2.PriorityParam) *HTTP2Settings
PriorityParam sets the priority parameter for HTTP/2.
func (*HTTP2Settings) Set ¶ added in v1.0.100
func (h *HTTP2Settings) Set() *Builder
Set applies the accumulated HTTP/2 settings. It configures the HTTP/2 settings for the surf client.
type HTTP3Settings ¶ added in v1.0.101
type HTTP3Settings struct {
// contains filtered or unexported fields
}
HTTP3Settings provides a fluent interface for configuring HTTP/3 SETTINGS parameters. These settings are sent to the server during connection establishment.
func (*HTTP3Settings) EnableConnectProtocol ¶ added in v1.0.155
func (h *HTTP3Settings) EnableConnectProtocol(num uint64) *HTTP3Settings
EnableConnectProtocol enables the extended CONNECT protocol (RFC 9220).
func (*HTTP3Settings) EnableWebtransport ¶ added in v1.0.155
func (h *HTTP3Settings) EnableWebtransport(num uint64) *HTTP3Settings
EnableWebtransport enables WebTransport support over HTTP/3.
func (*HTTP3Settings) Grease ¶ added in v1.0.155
func (h *HTTP3Settings) Grease() *HTTP3Settings
Grease adds a GREASE parameter with random ID and value to prevent protocol ossification.
func (*HTTP3Settings) H3Datagram ¶ added in v1.0.155
func (h *HTTP3Settings) H3Datagram(num uint64) *HTTP3Settings
H3Datagram sets a custom H3_DATAGRAM value for datagram support.
func (*HTTP3Settings) MaxFieldSectionSize ¶ added in v1.0.155
func (h *HTTP3Settings) MaxFieldSectionSize(num uint64) *HTTP3Settings
MaxFieldSectionSize sets the maximum size of a field section the peer is willing to accept.
func (*HTTP3Settings) QpackBlockedStreams ¶ added in v1.0.155
func (h *HTTP3Settings) QpackBlockedStreams(num uint64) *HTTP3Settings
QpackBlockedStreams sets the maximum number of streams that can be blocked on QPACK.
func (*HTTP3Settings) QpackMaxTableCapacity ¶ added in v1.0.155
func (h *HTTP3Settings) QpackMaxTableCapacity(num uint64) *HTTP3Settings
QpackMaxTableCapacity sets the maximum dynamic table capacity for QPACK.
func (*HTTP3Settings) Set ¶ added in v1.0.101
func (h *HTTP3Settings) Set() *Builder
Set applies the configured HTTP/3 settings to the client's transport.
func (*HTTP3Settings) SettingsH3Datagram ¶ added in v1.0.155
func (h *HTTP3Settings) SettingsH3Datagram(num uint64) *HTTP3Settings
SettingsH3Datagram sets the H3_DATAGRAM setting value.
type Headers ¶ added in v1.0.51
Headers represents a collection of HTTP Headers.
func (Headers) Contains ¶ added in v1.0.51
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.
func (Headers) Del ¶ added in v1.0.164
Del deletes the values associated with a specified header key. It wraps the Del method from the textproto.MIMEHeader type.
type Impersonate ¶ added in v1.0.100
type Impersonate struct {
// contains filtered or unexported fields
}
func (*Impersonate) Android ¶ added in v1.0.100
func (im *Impersonate) Android() *Impersonate
Android sets the OS to Android.
func (*Impersonate) Chrome ¶ added in v1.0.100
func (im *Impersonate) Chrome() *Builder
Chrome impersonates Chrome browser v144.
func (*Impersonate) Firefox ¶ added in v1.0.156
func (im *Impersonate) Firefox() *Builder
Firefox impersonates Firefox browser v147.
func (*Impersonate) FirefoxPrivate ¶ added in v1.0.156
func (im *Impersonate) FirefoxPrivate() *Builder
FirefoxPrivate impersonates Firefox private browser v147.
func (*Impersonate) IOS ¶ added in v1.0.100
func (im *Impersonate) IOS() *Impersonate
IOS sets the OS to iOS.
func (*Impersonate) Linux ¶ added in v1.0.100
func (im *Impersonate) Linux() *Impersonate
Linux sets the OS to Linux.
func (*Impersonate) MacOS ¶ added in v1.0.100
func (im *Impersonate) MacOS() *Impersonate
MacOS sets the OS to macOS.
func (*Impersonate) RandomOS ¶ added in v1.0.100
func (im *Impersonate) RandomOS() *Impersonate
RandomOS selects a random OS (Windows, macOS, Linux, Android, or iOS) for the impersonate.
func (*Impersonate) Windows ¶ added in v1.0.100
func (im *Impersonate) Windows() *Impersonate
Windows sets the OS to Windows.
type ImpersonateOS ¶ added in v1.0.100
type ImpersonateOS int
ImpersonateOS defines the operating system to impersonate in User-Agent strings.
type JA ¶ added in v1.0.100
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) Android ¶ added in v1.0.100
Android sets the JA3/4 fingerprint to mimic Android 11 OkHttp client.
func (*JA) Chrome ¶ added in v1.0.100
Chrome sets the JA3/4 fingerprint to mimic the latest Chrome browser (auto-detection).
func (*JA) Chrome100 ¶ added in v1.0.100
Chrome100 sets the JA3/4 fingerprint to mimic Chrome version 100.
func (*JA) Chrome102 ¶ added in v1.0.100
Chrome102 sets the JA3/4 fingerprint to mimic Chrome version 102.
func (*JA) Chrome106 ¶ added in v1.0.100
Chrome106 sets the JA3/4 fingerprint to mimic Chrome version 106 with shuffled extensions.
func (*JA) Chrome120 ¶ added in v1.0.100
Chrome120 sets the JA3/4 fingerprint to mimic Chrome version 120.
func (*JA) Chrome120PQ ¶ added in v1.0.100
Chrome120PQ sets the JA3/4 fingerprint to mimic Chrome version 120 with post-quantum cryptography support.
func (*JA) Chrome144 ¶ added in v1.0.167
Chrome144 sets the JA3/4 fingerprint to mimic Chrome version 144.
func (*JA) Chrome58 ¶ added in v1.0.100
Chrome58 sets the JA3/4 fingerprint to mimic Chrome version 58.
func (*JA) Chrome62 ¶ added in v1.0.100
Chrome62 sets the JA3/4 fingerprint to mimic Chrome version 62.
func (*JA) Chrome70 ¶ added in v1.0.100
Chrome70 sets the JA3/4 fingerprint to mimic Chrome version 70.
func (*JA) Chrome72 ¶ added in v1.0.100
Chrome72 sets the JA3/4 fingerprint to mimic Chrome version 72.
func (*JA) Chrome83 ¶ added in v1.0.100
Chrome83 sets the JA3/4 fingerprint to mimic Chrome version 83.
func (*JA) Chrome87 ¶ added in v1.0.100
Chrome87 sets the JA3/4 fingerprint to mimic Chrome version 87.
func (*JA) Chrome96 ¶ added in v1.0.100
Chrome96 sets the JA3/4 fingerprint to mimic Chrome version 96.
func (*JA) Edge ¶ added in v1.0.100
Edge sets the JA3/4 fingerprint to mimic Microsoft Edge version 85.
func (*JA) Edge106 ¶ added in v1.0.100
Edge106 sets the JA3/4 fingerprint to mimic Microsoft Edge version 106.
func (*JA) Edge85 ¶ added in v1.0.100
Edge85 sets the JA3/4 fingerprint to mimic Microsoft Edge version 85.
func (*JA) Firefox ¶ added in v1.0.100
Firefox sets the JA3/4 fingerprint to mimic the latest Firefox browser (auto-detection).
func (*JA) Firefox102 ¶ added in v1.0.100
Firefox102 sets the JA3/4 fingerprint to mimic Firefox version 102.
func (*JA) Firefox105 ¶ added in v1.0.100
Firefox105 sets the JA3/4 fingerprint to mimic Firefox version 105.
func (*JA) Firefox120 ¶ added in v1.0.100
Firefox120 sets the JA3/4 fingerprint to mimic Firefox version 120.
func (*JA) Firefox141 ¶ added in v1.0.122
Firefox141 sets the JA3/4 fingerprint to mimic Firefox version 141.
func (*JA) Firefox147 ¶ added in v1.0.167
Firefox147 sets the JA3/4 fingerprint to mimic Firefox version 147.
func (*JA) Firefox55 ¶ added in v1.0.100
Firefox55 sets the JA3/4 fingerprint to mimic Firefox version 55.
func (*JA) Firefox56 ¶ added in v1.0.100
Firefox56 sets the JA3/4 fingerprint to mimic Firefox version 56.
func (*JA) Firefox63 ¶ added in v1.0.100
Firefox63 sets the JA3/4 fingerprint to mimic Firefox version 63.
func (*JA) Firefox65 ¶ added in v1.0.100
Firefox65 sets the JA3/4 fingerprint to mimic Firefox version 65.
func (*JA) Firefox99 ¶ added in v1.0.100
Firefox99 sets the JA3/4 fingerprint to mimic Firefox version 99.
func (*JA) FirefoxPrivate147 ¶ added in v1.0.167
FirefoxPrivate147 sets the JA3/4 fingerprint to mimic Firefox private version 147.
func (*JA) IOS ¶ added in v1.0.100
IOS sets the JA3/4 fingerprint to mimic the latest iOS Safari browser (auto-detection).
func (*JA) Randomized ¶ added in v1.0.100
Randomized sets a completely randomized JA3/4 fingerprint.
func (*JA) RandomizedALPN ¶ added in v1.0.100
RandomizedALPN sets a randomized JA3/4 fingerprint with ALPN (Application-Layer Protocol Negotiation).
func (*JA) RandomizedNoALPN ¶ added in v1.0.100
RandomizedNoALPN sets a randomized JA3/4 fingerprint without ALPN.
func (*JA) Safari ¶ added in v1.0.100
Safari sets the JA3/4 fingerprint to mimic the latest Safari browser (auto-detection).
func (*JA) SetHelloID ¶ added in v1.0.100
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 ¶ added in v1.0.100
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)
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 {
Headers Headers // Response headers with convenience methods
Cookies Cookies // Response cookies with enhanced functionality
UserAgent g.String // User agent that was used for the request
Proto g.String // HTTP protocol version (HTTP/1.1, HTTP/2, HTTP/3)
*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
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 ¶ added in v1.0.47
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 ¶ added in v1.0.47
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 ¶ added in v1.0.47
func (s StatusCode) IsClientError() bool
IsClientError returns true if the status code indicates a client error [400, 500].
func (StatusCode) IsInformational ¶ added in v1.0.47
func (s StatusCode) IsInformational() bool
IsInformational returns true if the status code is in the informational range [100, 200].
func (StatusCode) IsRedirection ¶ added in v1.0.47
func (s StatusCode) IsRedirection() bool
IsRedirection returns true if the status code indicates a redirection [300, 400].
func (StatusCode) IsServerError ¶ added in v1.0.47
func (s StatusCode) IsServerError() bool
IsServerError returns true if the status code indicates a server error [500, ∞].
func (StatusCode) IsSuccess ¶ added in v1.0.47
func (s StatusCode) IsSuccess() bool
IsSuccess returns true if the status code indicates a successful response [200, 300].
func (StatusCode) Text ¶ added in v1.0.47
func (s StatusCode) Text() string
Text returns the textual representation of the status code.
type TLSData ¶ added in v1.0.100
type TLSData struct {
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.
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.
}
TLSData represents information about a TLS certificate.
type TransportAdapter ¶ added in v1.0.100
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 ¶ added in v1.0.100
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
|
|