Documentation
¶
Overview ¶
Package profiles defines the shared variant contract used by browser profile packages (profiles/chrome, profiles/firefox, ...) and consumed by the top-level surf package.
A Variant is the self-contained description of one browser and form-factor combination: TLS ClientHello, HTTP/2 + HTTP/3 SETTINGS, header set, User-Agent / sec-ch-ua data per OS. The surf.Impersonate dispatcher reads chrome.Desktop / chrome.Mobile / firefox.Desktop / firefox.Mobile values, applies the static fields, and runs ConfigureH2/ConfigureH3 against adapters that satisfy H2Config / H3Config — without the profile package importing surf.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SortByOrder ¶
func SortByOrder[T ~string](h *g.MapOrd[T, T], method string, enums g.Map[string, g.MapOrd[string, g.Int]])
SortByOrder reorders headers in-place according to the per-method enum positions returned by HeaderCache.Enums. Profile packages call it from headersDesktop / headersMobile after the browser-specific Insert step. Falls back to the GET enum when method is not present.
Types ¶
type H2Config ¶
type H2Config interface {
HeaderTableSize(uint32) H2Config
EnablePush(uint32) H2Config
MaxConcurrentStreams(uint32) H2Config
InitialWindowSize(uint32) H2Config
MaxFrameSize(uint32) H2Config
MaxHeaderListSize(uint32) H2Config
NoRFC7540Priorities(uint32) H2Config
ConnectionFlow(uint32) H2Config
InitialStreamID(uint32) H2Config
PriorityParam(http2.PriorityParam) H2Config
PriorityFrames([]http2.PriorityFrame) H2Config
}
H2Config is the fluent contract used by profile.ConfigureH2 callbacks. It mirrors the methods on surf.HTTP2Settings, the surf package provides an adapter that satisfies it.
type H3Config ¶
type H3Config interface {
QpackMaxTableCapacity(uint64) H3Config
MaxFieldSectionSize(uint64) H3Config
QpackBlockedStreams(uint64) H3Config
EnableConnectProtocol(uint64) H3Config
SettingsH3Datagram(uint64) H3Config
H3Datagram(uint64) H3Config
EnableWebtransport(uint64) H3Config
Grease() H3Config
}
H3Config is the fluent contract used by profile.ConfigureH3 callbacks. It mirrors the methods on surf.HTTP3Settings, the surf package provides an adapter that satisfies it.
type HeaderCache ¶
type HeaderCache struct {
// contains filtered or unexported fields
}
HeaderCache lazily builds and caches per-method header-position enums for both desktop and mobile header-order maps. Each browser profile constructs one HeaderCache from its own headerOrderDesktop / headerOrderMobile literals. The dispatcher asks for enums via Enums(mobile).
func NewHeaderCache ¶
NewHeaderCache wires the cache to two header-order maps. Enums are built on first access.
type HeadersApplier ¶
HeadersApplier applies the browser-specific request-header pipeline (insert defaults + reorder by header-order map) to a request header map. Form-factor (desktop/mobile) is baked into each applier instance — Variant.Desktop and Variant.Mobile carry different appliers.
func NewApplier ¶
func NewApplier( insertG HeadersFn[g.String], insertS HeadersFn[string], cache *HeaderCache, mobile bool, ) HeadersApplier
NewApplier wraps a browser-specific header-insert pair with the standard "insert, then reorder by per-method enum" pipeline shared by every profile. The form factor (desktop/mobile) is baked in via cache.Enums(mobile); the lookup runs on each call so HeaderCache lazy-init is preserved.
The constructor takes the two concrete HeadersFn instantiations as separate parameters so callers can pass the same generic function twice and let Go infer T at each site.
type HeadersFn ¶
HeadersFn is the type of a generic headers function instantiated for a concrete T ~string.
type OSKey ¶
type OSKey int
OSKey identifies the impersonated operating system. Surf's Impersonate stores it directly (no separate ImpersonateOS enum). Profile packages use it as a lookup key for UA / Platform.
type Variant ¶
type Variant struct {
// HelloSpec takes precedence over HelloID when non-nil.
HelloSpec *utls.ClientHelloSpec
HelloID utls.ClientHelloID
// Boundary is the multipart boundary generator for this browser. Same reference for both
// Desktop and Mobile within one profile package (boundary is a per-browser property).
Boundary func() g.String
// ConfigureH2 / ConfigureH3 own the fluent SETTINGS chain as code. The surf dispatcher
// invokes them with adapters and calls Set() afterwards.
ConfigureH2 func(H2Config)
ConfigureH3 func(H3Config)
// BuildHeaders constructs the full ordered header map for one request — pseudo-headers,
// Accept-Encoding, Accept-Language, authorization/cookie/origin/referer placeholders,
// sec-ch-ua-* (Chromium only), User-Agent. Profile packages provide one BuildHeaders per
// Variant so each browser and form-factor has its own single point of substitution for the
// entire header set (set, values, and order are all browser-specific).
BuildHeaders func(OSKey) *g.MapOrd[g.String, g.String]
// Headers applies the per-request header-order pipeline (the same Headers[T ~string]
// function profile packages export) for the surf request path. Same value for Desktop and
// Mobile within one profile package — header pipeline differs by mobile bool, not by
// Variant — but living on Variant lets surf.Builder route through one indirection without
// importing concrete profile packages from the request hot path.
Headers HeadersApplier
}
Variant is a self-contained description of one browser and form-factor combination.