eidolon

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

EIDOLON

A faithful, fingerprint-aware HTTP client for Go.

Don't just look alike. Behave alike.

Português

Eidolon sends HTTP requests the way a real browser does. It copies more than the fingerprint: the TLS ClientHello, the HTTP/2 settings, frames and priorities, and the header order and spelling. It also behaves like the browser: how it uses connections, retries, redirects, resumes TLS sessions, negotiates Encrypted Client Hello and goes through proxies. Each behavior is checked against the browser's source and against captures of its traffic.

It is built for crawlers, which usually run behind proxies.

Install

go get github.com/acomerlatto/eidolon-tls

It needs Go 1.27.2 or later. The TLS stack is a fork of uTLS, github.com/acomerlatto/utls, required as a module: no replace directive is needed.

Use

c, err := eidolon.New(eidolon.WithProfile(eidolon.Chrome156Linux()))
if err != nil {
	log.Fatal(err)
}
defer c.Close()

resp, err := c.Get("https://example.com/")
if err != nil {
	log.Fatal(err)
}
defer resp.Body.Close()

The API uses the standard net/http types. c.Transport() is an http.RoundTripper for code that builds its own http.Client.

The examples show HTTP/2, a custom profile built from a captured ClientHello and an Akamai fingerprint, ECH in automatic and required mode, and a proxy.

What it reproduces

  • Profile: Chrome 156 on Linux, built in. Other browsers and versions are made with Profile, ClientHelloFromRaw and ParseAkamai.
  • TLS: TLS 1.3 and 1.2, a new ClientHello for each connection with Chrome's extension shuffling and GREASE, and Chrome's TLS session cache.
  • ECH: in automatic mode (Chrome's default), required or off, with the configuration from DNS HTTPS records (the system resolver on Linux, or DNS over HTTPS) or set by hand. The ClientHelloInner is built as BoringSSL builds it.
  • HTTP/2: Chrome's SETTINGS, WINDOW_UPDATE, priorities, HPACK, header framing, error handling, ALPS and PING behavior.
  • HTTP/1.1: header order and spelling, connection pooling and limits.
  • Headers: the profile's headers per request destination (WithFetchDest), Sec-Fetch-* and Origin as the Fetch standard sets them, and an exact mode that sends only the given fields, in their order.
  • Proxies: HTTP (CONNECT), HTTPS, SOCKS4/4a and SOCKS5/5h, with one connection per request as an option for rotating proxies.
  • Redirects and cookies: redirects as the Fetch standard and Chrome follow them, and an optional cookie jar with the public suffix list.

Limits

What Eidolon does not do, and where it differs from Chrome, is listed in LIMITS.md. The main points: no HTTP/3, no revocation checking, certificates verified against Go's roots, and verified on Linux x86_64 only.

Upstreams

The HTTP/2 engine is a copy of golang.org/x/net/http2 with local patches, and the TLS stack is a fork of uTLS. UPSTREAM.md lists them and describes how their security fixes reach Eidolon.

License

MIT, see LICENSE. The code copied from golang.org/x/net, in internal/, keeps its BSD-3-Clause license.

Documentation

Overview

Package eidolon is an HTTP client for Go that reproduces the connections of real browsers: TLS ClientHello, HTTP/2 frames and settings, and header order and spelling in HTTP/2 and HTTP/1.1.

The API uses the standard net/http types. New returns an HttpClient; its Transport also works inside any http.Client.

A client resumes TLS sessions as Chrome: the sessions the servers give are kept per origin, for the 1024 origins used last, two each; a TLS 1.3 session is used once, for 48 hours at most and 7 days of resumptions from a full handshake, and a TLS 1.2 one for an hour from its full handshake. Clients share none. With ECH, as Chrome, the session goes in ClientHelloInner only, and a TLS 1.2 session is not offered.

Response.TLS is converted from the uTLS connection state. Its ExportKeyingMaterial cannot reach the connection and panics if called.

What the client does not do, and where it differs from Chrome, is listed in LIMITS.md at the root of the repository.

Index

Examples

Constants

View Source
const (
	HTTP2SettingHeaderTableSize       uint16 = 0x1
	HTTP2SettingEnablePush            uint16 = 0x2
	HTTP2SettingMaxConcurrentStreams  uint16 = 0x3
	HTTP2SettingInitialWindowSize     uint16 = 0x4
	HTTP2SettingMaxFrameSize          uint16 = 0x5
	HTTP2SettingMaxHeaderListSize     uint16 = 0x6
	HTTP2SettingEnableConnectProtocol uint16 = 0x8
	HTTP2SettingNoRFC7540Priorities   uint16 = 0x9
)

The SETTINGS parameters of RFC 9113 section 6.5.2, RFC 8441 and RFC 9218.

View Source
const (
	HeaderOrderKey  = order.HeaderKey
	PHeaderOrderKey = order.PseudoKey
)

HeaderOrderKey and PHeaderOrderKey are keys of Request.Header that set the order of a request, as in fhttp (tls-client) and the sardanioss x/net fork:

req.Header[eidolon.HeaderOrderKey] = []string{"accept", "user-agent", "accept-language"}
req.Header[eidolon.PHeaderOrderKey] = []string{":method", ":authority", ":scheme", ":path"}

HeaderOrderKey orders the regular headers and PHeaderOrderKey the HTTP/2 pseudo-headers. Both are optional and are never sent: the transport reads them from a copy of Request.Header without changing the caller's. http.Client copies them to a redirected request, so the order follows it. See Order for how names are compared and completed.

Variables

View Source
var (
	// ErrConfig reports an invalid option or a missing required one.
	ErrConfig = errors.New("eidolon: invalid configuration")
	// ErrClosed reports a request on a closed client.
	ErrClosed = dispatch.ErrClosed
	// ErrProfile reports a ClientHello spec that cannot be used: the
	// WithClientHello function failed or returned nil, the spec sets the
	// SNI name, it offers none of the enabled protocols, or uTLS refused
	// to apply it. New checks one spec; a later one that fails is
	// reported by the request, before any connection is opened.
	ErrProfile = tlsdial.ErrProfile
	// ErrALPN reports a protocol negotiated by ALPN that no engine handles.
	ErrALPN = tlsdial.ErrALPN
	// ErrProtocolPolicy reports a protocol outside the ones enabled by
	// WithProtocols or WithForceHTTP*: negotiated by the server, required
	// by it (HTTP_1_1_REQUIRED), or needed by the URL (http:// needs
	// HTTP/1.1).
	ErrProtocolPolicy = dispatch.ErrProtocolPolicy
	// ErrExactHeadersRedirect reports a redirect of a request sent with
	// WithExactHeaders; see there.
	ErrExactHeadersRedirect = dispatch.ErrExactHeadersRedirect
	// ErrCertificate reports a server certificate refused by verification:
	// unknown authority, wrong name, expired. The crypto/x509 error stays
	// in the chain, for errors.As with x509.UnknownAuthorityError,
	// x509.HostnameError or x509.CertificateInvalidError.
	ErrCertificate = tlsdial.ErrCertificate
	// ErrECHRequired reports a request, with ECHRequired, to an origin
	// without an ECH configuration, from WithECHConfig or its HTTPS record
	// (WithDoH or the name servers of the system), or with none the client
	// can use, or to an http:// URL: no connection to the origin is
	// opened. It also reports, with ErrECHRejected, a server that rejected
	// ECH without usable retry configurations, after that connection.
	ErrECHRequired = dispatch.ErrECHRequired
	// ErrECHRejected reports a server that rejected ECH also on the
	// connection that retried it (see ECHAuto), or, with ECHRequired,
	// without usable retry configurations. The utls.ECHRejectionError
	// stays in the chain; no HTTP byte is sent.
	ErrECHRejected = tlsdial.ErrECHRejected
	// ErrDNS reports, with ECHRequired, an HTTPS record that could not be
	// looked up (WithDoH or the name servers of the system): the server
	// could not be reached, answered SERVFAIL or a malformed response, or
	// not in time. In any mode, it
	// also reports an HTTPS record whose services all have ECH and none an
	// enabled protocol, which Chrome does not connect without. No
	// connection to the origin is opened.
	ErrDNS = dispatch.ErrDNS
	// ErrInvalidECHConfig reports an HTTPS record whose ECHConfigList
	// cannot be read, which fails the request as in Chrome. No connection
	// to the origin is opened.
	ErrInvalidECHConfig = dispatch.ErrInvalidECHConfig
	// ErrProxy reports a proxy (WithProxy) that could not be reached or
	// refused the tunnel; no byte of the request reached the destination.
	ErrProxy = proxy.ErrProxy
	// ErrProxyAuth reports a proxy that refused the credentials of its URL,
	// or asked for credentials the URL does not have.
	ErrProxyAuth = proxy.ErrProxyAuth
	// ErrTLS12Policy reports a TLS 1.2 connection refused by
	// WithStrictTLS12.
	ErrTLS12Policy = tlsdial.ErrTLS12Policy
	// ErrHTTP2InadequateSecurity reports a server that negotiated HTTP/2
	// over TLS 1.2 with a cipher suite HTTP/2 forbids, without AEAD or
	// with RSA key exchange. As Chrome, the client closes the connection
	// with GOAWAY INADEQUATE_SECURITY.
	ErrHTTP2InadequateSecurity = dispatch.ErrHTTP2InadequateSecurity
	// ErrMalformedResponse reports an HTTP/1.1 response that cannot be
	// read: a bad status line or header, conflicting Content-Length
	// values, more than five 1xx responses. A connection lost while
	// reading is not one.
	ErrMalformedResponse = http1.ErrMalformedResponse
	// ErrHeaderTooLarge reports response headers over the limit, 256 KiB
	// as Chrome, over HTTP/1.1 (1xx responses included) and HTTP/2.
	ErrHeaderTooLarge = http1.ErrHeaderTooLarge
	// ErrRetryBudget reports a request that could have been sent again
	// but was not, because its budget ran out: two retries of a request
	// the server did not process, as Chrome; one replay after an idle
	// HTTP/2 connection was lost, as the server might have processed it;
	// three replays over HTTP/1.1 or three dials. It wraps the last error.
	ErrRetryBudget = dispatch.ErrRetryBudget
	// ErrTooManyRedirects reports a request stopped after 20 redirects,
	// the limit of the Fetch standard and Chrome.
	ErrTooManyRedirects = errors.New("eidolon: stopped after 20 redirects")
)

Errors returned by the client, wrapped with context. Test them with errors.Is; http.Client wraps transport errors in *url.Error, which unwraps to them.

Functions

func Akamai

func Akamai(s HTTP2Settings, pseudo []string) string

Akamai returns the Akamai fingerprint of the start of an HTTP/2 connection with s and the pseudo-header order pseudo, as the tracker of peet.ws (TrackMe) writes it: SETTINGS|WINDOW_UPDATE|PRIORITY|PSEUDO. SETTINGS are id:value in order, joined with ";"; WINDOW_UPDATE is the connection increment, "00" for none; PRIORITY lists the PRIORITY frames as stream:exclusive:dependency:weight, with the weight from 1 to 256, joined with ",", or "0" for none; PSEUDO is the second letter of each pseudo-header field, joined with ",". The priority of HEADERS and the other fields of s are not part of it.

The Chrome 156 profile gives "1:65536;2:0;4:6291456;6:262144|15663105|0|m,a,s,p".

func ClientHelloFromRaw

func ClientHelloFromRaw(raw []byte, opts ...ClientHelloOption) (func() (*utls.ClientHelloSpec, error), error)

ClientHelloFromRaw returns a ClientHello function, for WithClientHello or Profile.ClientHello, that rebuilds a captured ClientHello for each connection: raw is the ClientHello handshake message, with or without its TLS record header. Each connection has new GREASE values, random, session ID and key shares; uTLS leaves the captured server name out of SNI, and the one sent is the host of the URL. The extensions keep the captured order unless WithShuffledExtensions is given. A captured pre_shared_key is left out, or carries a session of the client when it resumes one; without it, pre_shared_key is added at the end when the ClientHello offers psk_key_exchange_modes, as Chrome does. A GREASE encrypted_client_hello of BoringSSL draws its payload length again, as Chrome; another keeps the captured one.

The ClientHello is checked once, as New checks every spec: an extension uTLS does not know, an extension twice, a malformed list, pre_shared_key other than last or without psk_key_exchange_modes, a cipher suite, group, signature scheme or certificate compression the stack does not implement, a capability it cannot honor (such as early_data), a key share outside supported_groups or two of one group, ALPS for a protocol ALPN does not offer, or TLS 1.3 without key_share, supported_groups or signature_algorithms return an error that wraps ErrProfile, and a nil option one that wraps ErrConfig. raw is copied.

func NewCookieJar

func NewCookieJar() http.CookieJar

NewCookieJar returns an empty cookie jar for WithCookieJar: the jar of net/http/cookiejar with the public suffix list, so a cookie cannot be set for a whole public suffix such as "co.uk".

func WithExactHeaders

func WithExactHeaders(ctx context.Context, fields ...HeaderField) context.Context

WithExactHeaders returns a context whose requests send exactly fields as their regular headers: in this order, repeated names where they are, and nothing else. Request.Header is ignored but for PHeaderOrderKey, and no field of the client, the cookie jar or the engines is added: not User-Agent, Accept-Encoding, Cookie or Connection. An empty list changes nothing. The list is copied.

Over HTTP/1.1 the names are sent spelled as given, and a Host field is required. Over HTTP/2 the names are lowercased, Host becomes :authority, connection-specific fields such as Connection are left out, and Cookie is not split. Pseudo-headers still follow the order (PHeaderOrderKey, then the client order).

Framing is checked, never corrected: a body needs a Content-Length field with its length over HTTP/1.1, and over HTTP/2 a Content-Length field, if any, must match it.

A redirect of such a request fails with ErrExactHeadersRedirect without sending anything: http.Client filters credentials out of Header only. Use CheckRedirect with http.ErrUseLastResponse and send the next request with its own fields.

func WithFetchDest

func WithFetchDest(ctx context.Context, dest FetchDest) context.Context

WithFetchDest returns a context that sends a request as the destination dest. With a profile, a request with a destination Sec-Fetch-Dest cannot send fails before it is sent. A redirect keeps the destination of the first request, as Chrome does.

Without it, the destination comes from the request: its Sec-Fetch-Dest, then its Sec-Fetch-Mode (navigate is a FetchDocument, any other mode a FetchEmpty), then an Accept of an API such as application/json or a bare */* (FetchEmpty), then the method: GET, HEAD and the POST of a form (application/x-www-form-urlencoded or multipart/form-data) are a FetchDocument, anything else a FetchEmpty.

Types

type ClientHelloOption

type ClientHelloOption func(*clientHelloConfig)

ClientHelloOption is an option of ClientHelloFromRaw.

func WithShuffledExtensions

func WithShuffledExtensions() ClientHelloOption

WithShuffledExtensions shuffles the extensions of each ClientHello as Chrome does since version 106 (utls.ShuffleChromeTLSExtensions): GREASE, padding and pre_shared_key keep their places.

type DestHeaders

type DestHeaders struct {
	// Mode is sent in Sec-Fetch-Mode, such as "navigate", "no-cors" or
	// "cors", over https:// only.
	Mode string
	// Accept and Priority are sent as given; "" sends none. Priority is
	// never sent over HTTP/1.1, as in Chrome.
	Accept, Priority string
	// User sends Sec-Fetch-User: ?1, as a navigation the user started,
	// over https:// only.
	User bool
	// UpgradeInsecureRequests sends Upgrade-Insecure-Requests: 1.
	UpgradeInsecureRequests bool
	// Navigation orders the headers by NavigationOrder.
	Navigation bool
}

DestHeaders are the headers a profile adds for one destination.

type ECHMode

type ECHMode int

ECHMode is the policy of Encrypted Client Hello (RFC 9849), as the EchMode of Chrome 156.

const (
	// ECHAuto, the default, offers ECH to an origin with an ECH
	// configuration, from WithECHConfig or else from its HTTPS record, and
	// sends the GREASE ECH of the profile to the others, as Chrome
	// (kOpportunistic). The record is asked to the server of WithDoH, or,
	// on Linux and a direct connection (no proxy, no WithDialContext), to
	// the name servers of the system as Chrome on Linux does: those of
	// /etc/resolv.conf, by UDP, unless Chrome would leave the resolution
	// to the system (use-vc, an nsswitch.conf it does not follow) or the
	// host is localhost or in /etc/hosts. The configuration is read when
	// the client is made; the name is asked as it is, without the search
	// list. A record that cannot be looked up, or whose
	// configurations the client cannot use, leaves the origin with GREASE;
	// one whose ECHConfigList cannot be read fails with
	// ErrInvalidECHConfig, as in Chrome. When the server
	// rejects ECH, authenticated by a certificate for the public name of
	// the configuration, the request goes over one new connection, within
	// the same dial deadline and to the same IP address (see
	// WithDialContext): with the retry configurations the server
	// sent, or, without usable ones, with the GREASE ECH of the profile,
	// as Chrome does (RFC 9849, Section 6.1.6, would disable ECH). The
	// rejected connection carries no HTTP byte; a second rejection fails
	// with ErrECHRejected. Retry configurations are not kept: the next
	// connection starts from WithECHConfig again.
	ECHAuto ECHMode = iota
	// ECHRequired completes a request only over a connection whose server
	// accepted ECH, as Chrome's kStrict: a request to an origin without an
	// ECH configuration, http:// included, fails with ErrECHRequired
	// before any dial, and GREASE ECH does not count. An HTTPS record that
	// could not be looked up fails with ErrDNS. A rejection is
	// retried as in ECHAuto with the retry configurations; without usable
	// ones, the request fails with ErrECHRequired and ErrECHRejected.
	ECHRequired
	// ECHDisabled never offers ECH. The profile still sends its GREASE
	// ECH: unlike Chrome's kDisabled, which leaves the extension out, the
	// fingerprint of the profile does not change.
	ECHDisabled
)

type FetchDest

type FetchDest string

FetchDest is the destination of a request in the Fetch standard, sent in Sec-Fetch-Dest: what the browser fetches it for. With a profile, it chooses the headers of the request; without one, nothing uses it.

The constants are the destinations whose headers come from a capture. The other values Sec-Fetch-Dest can send, such as "font", "iframe" or "worker", are accepted too.

const (
	// FetchDocument is a navigation: a link followed, an address typed, a
	// form submitted.
	FetchDocument FetchDest = "document"
	// FetchEmpty is a request of fetch() or XMLHttpRequest.
	FetchEmpty FetchDest = "empty"
	// FetchStyle is a stylesheet.
	FetchStyle FetchDest = "style"
	// FetchScript is a script.
	FetchScript FetchDest = "script"
	// FetchImage is an image.
	FetchImage FetchDest = "image"
)

type HTTP2ALPS

type HTTP2ALPS int

HTTP2ALPS is how an HTTP/2 connection reads the ALPS of the server, the HTTP/2 frames the server sends in the TLS handshake when the ClientHello offers ALPS (application_settings) for h2.

const (
	// HTTP2ALPSIgnore ignores them, as Go, which has no ALPS.
	HTTP2ALPSIgnore HTTP2ALPS = iota
	// HTTP2ALPSChromium reads them as Chromium, before the first frame of
	// the server: their SETTINGS apply as those of a SETTINGS frame,
	// without ACK, and malformed ALPS, such as a frame other than SETTINGS
	// or ACCEPT_CH, closes the connection with GOAWAY PROTOCOL_ERROR
	// "Error parsing ALPS: N" and fails the request. ACCEPT_CH is not
	// used.
	HTTP2ALPSChromium
)

type HTTP2Errors

type HTTP2Errors int

HTTP2Errors is how an HTTP/2 connection handles the errors of the server: frames, header blocks, settings or windows it does not accept.

const (
	// HTTP2ErrorsGo handles them as Go: most close the connection with
	// GOAWAY, without debug data.
	HTTP2ErrorsGo HTTP2Errors = iota
	// HTTP2ErrorsChromium handles them as Chromium: those it takes as
	// connection errors close the connection with its GOAWAY code and
	// debug data, such as "Framer error: 1 (INVALID_STREAM_ID).", those
	// it takes as stream errors reset the stream, and those it ignores,
	// such as an invalid INITIAL_WINDOW_SIZE, are ignored. A connection
	// lost to PrefacePing is closed with GOAWAY "Failed ping.". As in
	// Chromium, at most 256 streams are open at once whatever
	// MAX_CONCURRENT_STREAMS says, and a first SETTINGS without it keeps
	// the initial limit of 100, where Go raises it to 1000.
	HTTP2ErrorsChromium
)

type HTTP2HPACK

type HTTP2HPACK int

HTTP2HPACK is how an HTTP/2 connection encodes header fields with HPACK (RFC 7541).

const (
	// HTTP2HPACKGo encodes as the HPACK encoder of Go: every field that
	// fits in the table is indexed, and the table never grows past 4096
	// bytes, with a size update whenever the server announces a size.
	HTTP2HPACKGo HTTP2HPACK = iota
	// HTTP2HPACKChromium encodes as Chromium (quiche's HpackEncoder): only
	// :authority among the pseudo-headers is indexed, and the table takes
	// any size the server announces, with a size update only when it
	// changes.
	HTTP2HPACKChromium
)

type HTTP2HeaderFraming

type HTTP2HeaderFraming int

HTTP2HeaderFraming is how a header block too large for one frame is cut into HEADERS and CONTINUATION frames.

const (
	// HTTP2HeaderFramingGo fills each frame up to the MAX_FRAME_SIZE of
	// the server, as Go.
	HTTP2HeaderFramingGo HTTP2HeaderFraming = iota
	// HTTP2HeaderFramingChromium sends frames of at most 16383 bytes with
	// their 9-byte header, whatever the MAX_FRAME_SIZE of the server, as
	// Chromium.
	HTTP2HeaderFramingChromium
)

type HTTP2Priority

type HTTP2Priority int

HTTP2Priority is how the requests of an HTTP/2 connection announce their priority in HEADERS.

const (
	// HTTP2PriorityNone sends HEADERS without the PRIORITY flag.
	HTTP2PriorityNone HTTP2Priority = iota
	// HTTP2PriorityChromium sends HEADERS with the PRIORITY flag as
	// Chromium: the weight follows the urgency of the request's priority
	// field (RFC 9218; 255, 219, 182, 146, 109, 73, 36, 0 for u=0 to 7,
	// u=3 without one), and the stream depends exclusively on the last
	// open stream of that urgency, or else of the closest more urgent one,
	// or else on stream 0.
	HTTP2PriorityChromium
	// HTTP2PriorityFixed sends every HEADERS with the PRIORITY flag and
	// HTTP2Settings.HeaderPriority, as Firefox up to version 88 did.
	HTTP2PriorityFixed
)

type HTTP2PriorityFrame

type HTTP2PriorityFrame struct {
	StreamID uint32
	HTTP2PriorityParam
}

HTTP2PriorityFrame is a PRIORITY frame sent before the first request.

type HTTP2PriorityParam

type HTTP2PriorityParam struct {
	StreamDep uint32
	Exclusive bool
	Weight    uint8
}

HTTP2PriorityParam is the priority of a stream, in a PRIORITY frame or in HEADERS (RFC 9113 section 6.3): the stream it depends on, whether the dependency is exclusive, and the weight as sent, one less than the weight (255 is 256).

type HTTP2Setting

type HTTP2Setting struct {
	ID    uint16
	Value uint32
}

HTTP2Setting is one parameter of the SETTINGS frame that starts an HTTP/2 connection (RFC 9113 section 6.5.2).

type HTTP2Settings

type HTTP2Settings struct {
	// Settings are sent exactly, in this order. Unknown IDs, such as
	// GREASE values, are sent as given. ENABLE_PUSH 0 is required: its
	// initial value, 1, would allow the server push the client refuses.
	Settings []HTTP2Setting
	// ConnectionWindowUpdate is the increment of the WINDOW_UPDATE sent on
	// the connection right after SETTINGS; 0 sends none.
	ConnectionWindowUpdate uint32
	// Priority is how the requests announce their priority.
	Priority HTTP2Priority
	// MaxDataFrameSize, if non-zero, limits the DATA frames of a request
	// body below the server's MAX_FRAME_SIZE: Chrome sends at most 16375
	// bytes, whatever the server allows.
	MaxDataFrameSize uint32
	// HPACK is how the header fields are encoded.
	HPACK HTTP2HPACK
	// PrefacePing, if non-zero, sends a PING right after the HEADERS of a
	// request, or a DATA frame with payload, when nothing has been read on
	// the connection for longer than it, as Chrome does after 10 s: at
	// most one at a time, with a payload counting the PINGs from 1. If
	// nothing is read for PrefacePing while it is unanswered, the
	// connection is closed as lost, and its requests fail.
	PrefacePing time.Duration
	// WindowUpdate is when the receive windows are given back.
	WindowUpdate HTTP2WindowUpdate
	// CancelWithoutPing sends the RST_STREAM of a cancelled request alone,
	// as Chrome. Otherwise, as in Go, when nothing has been read since the
	// request was sent, a PING goes with it, and the stream keeps its
	// place in the server's concurrency limit until the PING is answered.
	CancelWithoutPing bool
	// PriorityFrames are sent in order right after SETTINGS and the
	// connection WINDOW_UPDATE, as Firefox up to version 88 built its
	// priority tree on idle streams. Chrome sends none.
	PriorityFrames []HTTP2PriorityFrame
	// HeaderPriority is the priority of every HEADERS with
	// HTTP2PriorityFixed.
	HeaderPriority HTTP2PriorityParam
	// FirstStreamID, if non-zero, is the stream of the first request,
	// above the streams of PriorityFrames; 0 is 1.
	FirstStreamID uint32
	// Errors is how the errors of the server are handled.
	Errors HTTP2Errors
	// ALPS is how the ALPS of the server is read.
	ALPS HTTP2ALPS
	// HeaderFraming is how large header blocks are cut into frames.
	HeaderFraming HTTP2HeaderFraming
}

HTTP2Settings is what a new HTTP/2 connection sends before its first request, how its requests announce their priority, how it sends DATA frames, header fields, PINGs, window updates and resets, and how it handles the errors of the server.

func ParseAkamai

func ParseAkamai(fp string, base HTTP2Settings) (HTTP2Settings, []string, error)

ParseAkamai reads an Akamai fingerprint, as the function Akamai writes it, into the SETTINGS, the connection WINDOW_UPDATE and the PRIORITY frames of base, and returns them with the pseudo-header order, for Profile.PseudoOrder. The other fields of base, such as Priority or HPACK, are kept: the fingerprint does not say them.

Besides what Akamai writes, SETTINGS may be joined with ",", and WINDOW_UPDATE may be "0" or empty for none. An empty SETTINGS part, or "0", is no setting. The pseudo-header letters are m, a, s and p, each at most once. The result is validated as WithHTTP2Settings validates, so a fingerprint without ENABLE_PUSH 0 is refused; every error wraps ErrConfig.

type HTTP2WindowUpdate

type HTTP2WindowUpdate int

HTTP2WindowUpdate is when an HTTP/2 connection gives back the receive windows of the connection and of its streams with WINDOW_UPDATE.

const (
	// HTTP2WindowUpdateGo gives the window back as Go does, every 4 KiB
	// read.
	HTTP2WindowUpdateGo HTTP2WindowUpdate = iota
	// HTTP2WindowUpdateChromium gives it back as Chromium: once more than
	// half of the window has been read, or 5 s after the last update,
	// when more is read.
	HTTP2WindowUpdateChromium
)

type HeaderField

type HeaderField struct {
	Name, Value string
}

HeaderField is one header field of exact mode.

type HttpClient

type HttpClient interface {
	// Do sends a request, as http.Client.Do. Redirects are followed as
	// the Fetch standard and Chrome do: up to 20, then ErrTooManyRedirects;
	// 301 and 302 turn only a POST into a GET, 303 anything but GET and
	// HEAD, and the other cases send the method and body again (GetBody).
	// A body without GetBody stops at the redirect, which is returned.
	//
	// Request.Close ends the connection after the request without sending
	// "Connection: close", which Chrome never sends: HTTP/1.1 closes it
	// once the response was read, HTTP/2 takes no new streams on it and
	// closes it when its streams end. A Connection field set by the caller
	// is sent on HTTP/1.1 and has the same effect, in exact mode
	// (WithExactHeaders) when it is among the fields sent.
	Do(req *http.Request) (*http.Response, error)
	// Get, Head and Post are the http.Client shortcuts.
	Get(url string) (*http.Response, error)
	Head(url string) (*http.Response, error)
	Post(url, contentType string, body io.Reader) (*http.Response, error)

	// GetCookies returns the cookies of the jar (WithCookieJar) for u, and
	// SetCookies stores cookies in it as if u had sent them. Without a jar
	// GetCookies returns nil and SetCookies does nothing.
	GetCookies(u *url.URL) []*http.Cookie
	SetCookies(u *url.URL, cookies []*http.Cookie)

	// CloseIdleConnections closes connections that carry no request. It
	// never interrupts a response in progress.
	CloseIdleConnections()
	// Close stops the client: new requests fail with ErrClosed and every
	// connection is closed, including responses still being read. The
	// lookups of HTTPS records in progress end, and none starts after.
	Close() error

	// Transport returns the RoundTripper used by the client, for code that
	// builds its own http.Client. It shares connections with the client.
	// WithTimeout is not part of it: the http.Client that uses it sets
	// its own timeout. That http.Client follows redirects by its own
	// rules: at most 10, and PUT, DELETE and PATCH turned into GET at 301
	// and 302. The transport still sets the Referer and drops the
	// credentials at each hop as the client does, cookies included: those
	// of the first request leave the chain once it changes origin. With a
	// jar in that http.Client, a cookie of the jar the first request also
	// sent leaves it too; the client's own redirects keep it.
	Transport() http.RoundTripper
}

HttpClient sends requests with the configured browser fingerprint.

func New

func New(opts ...Option) (HttpClient, error)

New returns a client configured by opts. WithClientHello is required. Invalid or missing options return an error that wraps ErrConfig. New calls the ClientHello function once and applies the spec without connecting: a profile that cannot be used also wraps ErrProfile.

Example

A client with the profile of Chrome 156 on Linux sends requests as that browser: its ClientHello, its HTTP/2 settings and its headers, in its order. The protocol is negotiated by ALPN, HTTP/2 when the server offers it.

package main

import (
	"fmt"
	"io"
	"log"

	eidolon "github.com/acomerlatto/eidolon-tls"
)

func main() {
	c, err := eidolon.New(eidolon.WithProfile(eidolon.Chrome156Linux()))
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	resp, err := c.Get("https://example.com/")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(resp.Proto, resp.Status, len(body))
}

type Option

type Option func(*config) error

Option configures a client in New. Options fill a private configuration that New validates; the client cannot be changed afterwards.

func WithClientHello

func WithClientHello(spec func() (*utls.ClientHelloSpec, error)) Option

WithClientHello sets the function that returns a new ClientHello spec for each connection. It is required: there is no default browser profile. The SNI extension must leave ServerName empty: the name sent and verified is always the host of the URL, and a spec that sets one fails the request. New builds one spec and refuses, with an error that wraps ErrProfile, a ClientHello the stack cannot honor or that contradicts itself, as listed in ClientHelloFromRaw, and an extension uTLS has a type for, such as SNI, ALPN or supported_versions, written as a utls.GenericExtension: sent as given, it would escape the URL's server name and WithForceHTTP1, and uTLS would keep none of its state. The TLS versions are the ones the spec offers: unlike Chrome, which refuses anything below TLS 1.2, a spec that offers TLS 1.0 or 1.1 negotiates them.

func WithCookieJar

func WithCookieJar(jar http.CookieJar) Option

WithCookieJar sets the cookie jar of the client's own methods, as http.Client.Jar does: cookies from Set-Cookie, including redirect responses, are stored, and those of each URL are added to its Cookie field. Without it there is no jar. NewCookieJar returns one with the public suffix list. It is not part of Transport(): the http.Client that uses it sets its own jar. In exact mode (WithExactHeaders) no cookie of the jar is sent.

func WithDefaultOrder

func WithDefaultOrder(o Order) Option

WithDefaultOrder sets the header order of the client's requests. The order of a request (HeaderOrderKey, PHeaderOrderKey) takes precedence; see Order. The lists are copied when WithDefaultOrder is called.

func WithDialContext

func WithDialContext(dial func(ctx context.Context, network, addr string) (net.Conn, error)) Option

WithDialContext sets the function that opens TCP connections. Without it, a zero net.Dialer is used, and the new connection after an ECH rejection goes to the IP address of the rejected one, as Chrome; with it, that connection gets the host name again, resolved as dial does.

func WithDisableDecompression

func WithDisableDecompression() Option

WithDisableDecompression delivers response bodies as the server sent them. By default a body with Content-Encoding gzip, deflate, br or zstd (windows up to 8 MiB, as Chrome) is decoded, as browsers do: the response loses Content-Encoding and Content-Length, and Response.Uncompressed is set. Other codings, and several codings, are always delivered as they came. Accept-Encoding is never added: it comes from the request or the profile.

func WithDisableHTTP3

func WithDisableHTTP3() Option

WithDisableHTTP3 leaves HTTP/3 out. It changes nothing yet: the client never uses QUIC.

func WithDoH

func WithDoH(template string, addrs ...string) Option

WithDoH sets the DNS over HTTPS server (RFC 8484) the client asks for the HTTPS records (RFC 9460) of its https:// origins, as Chrome with secure DNS: the record of an origin gives its ECH configuration, which ECHAuto and ECHRequired use. Without WithDoH, a client on Linux that connects directly asks the name servers of the system, as Chrome's built-in client (see WithECHMode); on other systems, through a proxy or WithDialContext, no HTTPS record is looked up and only WithECHConfig gives ECH configurations.

template is the URI template of the server: an https:// URL with the variable dns ({?dns}, {&dns} or {dns}), whose queries go by GET, or without variables, by POST. They go as Chrome sends them: its minimal header fields over connections with the profile's ClientHello and HTTP/2 settings and GREASE ECH, the certificate verified for the host of the template, through the proxy of WithProxy, which resolves that host. Without a proxy, addrs are the IP addresses of the server, dialed in turn, each with an equal share of the time left, the next one after a failed connection or TLS handshake: the server is never looked up in DNS. Redirects are not followed, where Chrome follows those to https://.

Over HTTP/2 the queries carry Priority: u=4, i, the IDLE priority of most DoH queries of Chrome, the navigations' included, and over HTTP/1.1 Connection: keep-alive.

Only the HTTPS records are asked: the addresses of the origins come from the proxy, or else from WithDialContext or the system resolver. As Chrome, localhost and its subdomains are not asked, nor, without a proxy, the names of the hosts file of the system. A lookup that fails or gets no answer within 12 seconds leaves the origin without ECH, unless ECHRequired. Answers are kept for their TTL, up to 1000 origins per client.

New refuses, with ErrConfig, a template it cannot use, addrs that are not IP addresses, no addrs without a proxy, ECHDisabled, and a profile that cannot offer ECH.

func WithECHConfig

func WithECHConfig(authority string, configList []byte) Option

WithECHConfig sets the ECHConfigList (RFC 9849, Section 4) of one origin, given by its authority: a host name, with an optional port, 443 by default. Connections to https://authority offer ECH with it: the ClientHelloOuter carries the public name of the configuration, and the ClientHelloInner, encrypted, the host name and the profile's extensions, built as Chrome builds them. No other origin uses it, including the other ports of the host and the targets of redirects.

New refuses, with ErrConfig, an IP address, an authority set twice, a list that cannot be read or has no configuration the client supports, a profile without the ECH extension, and ECHDisabled. The list is copied when WithECHConfig is called.

func WithECHMode

func WithECHMode(m ECHMode) Option

WithECHMode sets the ECH policy; the default is ECHAuto.

Example (Auto)

In the default mode, ECHAuto, an origin whose HTTPS record carries an ECH configuration gets ECH, and the others the GREASE ECH of the profile, as Chrome. WithDoH asks the records to a DNS over HTTPS server, here Cloudflare's at its IP addresses; without it, a client on Linux asks the name servers of the system.

package main

import (
	"fmt"
	"log"

	eidolon "github.com/acomerlatto/eidolon-tls"
)

func main() {
	c, err := eidolon.New(
		eidolon.WithProfile(eidolon.Chrome156Linux()),
		eidolon.WithDoH("https://cloudflare-dns.com/dns-query{?dns}", "1.1.1.1", "1.0.0.1"),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	resp, err := c.Get("https://crypto.cloudflare.com/cdn-cgi/trace")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
	fmt.Println("ECH accepted:", resp.TLS.ECHAccepted)
}
Example (Required)

With ECHRequired, a request completes only over a connection whose server accepted ECH: an origin without an ECH configuration fails with ErrECHRequired before any connection.

package main

import (
	"errors"
	"fmt"
	"log"

	eidolon "github.com/acomerlatto/eidolon-tls"
)

func main() {
	c, err := eidolon.New(
		eidolon.WithProfile(eidolon.Chrome156Linux()),
		eidolon.WithDoH("https://cloudflare-dns.com/dns-query{?dns}", "1.1.1.1", "1.0.0.1"),
		eidolon.WithECHMode(eidolon.ECHRequired),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	resp, err := c.Get("https://example.com/")
	switch {
	case errors.Is(err, eidolon.ErrECHRequired):
		fmt.Println("no ECH for this origin")
	case err != nil:
		log.Fatal(err)
	default:
		resp.Body.Close()
		fmt.Println("ECH accepted:", resp.TLS.ECHAccepted) // always true
	}
}

func WithForceHTTP1

func WithForceHTTP1() Option

WithForceHTTP1 enables only HTTP/1.1, as WithProtocols(HTTP1).

func WithForceHTTP2

func WithForceHTTP2() Option

WithForceHTTP2 enables only HTTP/2, as WithProtocols(HTTP2). URLs with the http scheme then fail: there is no HTTP/2 over cleartext.

Example

WithForceHTTP2 offers only h2 in ALPN: a server that does not negotiate it fails the request instead of answering over HTTP/1.1, with ErrProtocolPolicy when it completes the handshake without ALPN.

package main

import (
	"fmt"
	"log"

	eidolon "github.com/acomerlatto/eidolon-tls"
)

func main() {
	c, err := eidolon.New(eidolon.WithProfile(eidolon.Chrome156Linux()), eidolon.WithForceHTTP2())
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	resp, err := c.Get("https://example.com/")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
	fmt.Println(resp.Proto) // HTTP/2.0
}

func WithHTTP2Settings

func WithHTTP2Settings(s HTTP2Settings) Option

WithHTTP2Settings sets the SETTINGS and the connection WINDOW_UPDATE of each new HTTP/2 connection. By default they are those of Chrome 156: HEADER_TABLE_SIZE 65536, ENABLE_PUSH 0, INITIAL_WINDOW_SIZE 6291456 and MAX_HEADER_LIST_SIZE 262144, then a WINDOW_UPDATE of 15663105, with HTTP2PriorityChromium, DATA frames of at most 16375 bytes, HTTP2HPACKChromium, a PrefacePing of 10 s, HTTP2WindowUpdateChromium, CancelWithoutPing, HTTP2ErrorsChromium, HTTP2ALPSChromium and HTTP2HeaderFramingChromium.

The values announced are enforced: HEADER_TABLE_SIZE sizes the HPACK decoder, INITIAL_WINDOW_SIZE the receive window of each stream, the window update that of the connection (65535 plus it), MAX_FRAME_SIZE the largest frame read and MAX_HEADER_LIST_SIZE the response headers. One left out keeps its RFC 9113 initial value; without MAX_HEADER_LIST_SIZE the response headers are still limited to 256 KiB. Invalid settings return an error that wraps ErrConfig: a setting repeated, a value RFC 9113 forbids, ENABLE_PUSH left out or other than 0 (server push is refused, and its initial value is 1), INITIAL_WINDOW_SIZE or MAX_HEADER_LIST_SIZE of 0, a connection window above 2^31-1, an unknown Priority, HPACK, WindowUpdate, Errors, ALPS or HeaderFraming, a negative PrefacePing, a PRIORITY frame on stream 0 or on its own stream, a stream ID above 2^31-1, an even FirstStreamID or one of 2^31-1, which no request could open, a HeaderPriority without HTTP2PriorityFixed, a zero one with it or one depending on a stream the requests open, or PriorityFrames, HTTP2PriorityFixed or HTTP2PriorityChromium with NO_RFC7540_PRIORITIES 1, which says the client sends no such priority. The settings are copied when WithHTTP2Settings is called.

func WithHeaderSpelling

func WithHeaderSpelling(names ...string) Option

WithHeaderSpelling sets how header names are spelled over HTTP/1.1, such as "sec-ch-ua" in lowercase next to "User-Agent". http.Header canonicalizes its keys, so the spelling of a name comes from here; names not listed are sent in canonical form. Over HTTP/2 names are always lowercase. The names are copied when WithHeaderSpelling is called.

func WithIdleConnTimeout

func WithIdleConnTimeout(d time.Duration) Option

WithIdleConnTimeout bounds how long an idle HTTP/1.1 connection is kept for reuse. The default is 300 seconds, as Chrome for a connection that served a request. HTTP/2 connections are kept until the server or CloseIdleConnections closes them, as Chrome does.

func WithMaxConns

func WithMaxConns(n int) Option

WithMaxConns bounds the connections of the client to every origin, in use, idle or being opened, as Chrome's socket pool counts them. A new connection over the limit first closes an idle HTTP/1.1 connection: of the first origin, in key order, that has one, the one it used least recently. Without one, as Chrome, it closes every HTTP/2 connection without streams, then waits for a connection to close, until its request ends, without counting the wait in the dial timeout; while it waits, an HTTP/2 connection also closes when its last stream ends. By default there is no limit, where Chrome has 256: a crawler would wait for connections where it expects none. The connections of WithDoH are not counted.

func WithMaxConnsPerHost

func WithMaxConnsPerHost(n int) Option

WithMaxConnsPerHost bounds the HTTP/1.1 connections per origin; requests over the limit wait for a connection, each until its own context ends. The default is 6, as Chrome. HTTP/2 uses one connection per origin.

func WithMaxDNSQueries

func WithMaxDNSQueries(n int) Option

WithMaxDNSQueries bounds the lookups of HTTPS records in progress at once, to the server of WithDoH or the name servers of the system; the others wait in line, each until its own context ends, and their 12 seconds start when they leave it. The default is 64, as Chrome's resolver jobs. Lookups of one origin share one query.

func WithNewConnectionPerRequest

func WithNewConnectionPerRequest() Option

WithNewConnectionPerRequest gives each request connections of its own, closed when its response body is read to its end or closed: none is reused, so a rotating proxy chooses a new exit for each request, a redirect hop included. Without it, connections are reused as Chrome reuses them. What the client learns from a connection, such as a server that requires HTTP/1.1, goes with it, and no TLS session is resumed: each request looks like a new browser to the server. The queries of WithDoH still reuse their connections, as Chrome keeps one to its DoH server.

func WithProfile

func WithProfile(p Profile) Option

WithProfile sets the profile of the client. The options that set one of its parts, such as WithClientHello or WithHTTP2Settings, take precedence over that part, whatever their position. A profile that cannot be used returns an error that wraps ErrConfig: invalid HTTP2 (see WithHTTP2Settings), a pseudo-header order with a name repeated or not a pseudo-header, an invalid spelling (see WithHeaderSpelling), an invalid header name or value, a destination Sec-Fetch-Dest cannot send or without Mode, or a negative MaxConnsPerHost or IdleConnTimeout. The profile is copied when WithProfile is called.

func WithProtocols

func WithProtocols(ps ...Protocol) Option

WithProtocols enables only the listed protocols. By default every protocol of the ClientHello spec is enabled. A server that negotiates, or requires, another one fails the request with ErrProtocolPolicy.

Leaving HTTP/1.1 or HTTP/2 out changes the ClientHello: ALPN offers only the enabled protocols, and ALPS only those ALPN still offers. The fingerprint is then no longer the one of the spec. It cannot be combined with WithForceHTTP1 or WithForceHTTP2. The list is copied when WithProtocols is called. The queries of WithDoH follow it too.

func WithProxy

func WithProxy(rawURL string) Option

WithProxy sends every connection through the proxy of rawURL, one per client: http://, https://, socks5:// (or socks5h://) and socks4:// (or socks4a://), with an optional user:password@ and port, 80 for http://, 443 for https:// and 1080 for SOCKS by default. The proxy resolves the destination.

An HTTPS proxy is reached over TLS with the ClientHello of the profile, its certificate verified as a server's, and ALPN offering http/1.1 only: Chrome also offers h2 and then tunnels over HTTP/2 streams. It is then used as an HTTP proxy. Its TLS sessions are resumed as an origin's, under a key of their own.

An HTTP proxy gets https:// requests over a CONNECT tunnel, with the User-Agent of the profile as Chrome sends it, and http:// requests as they are, as Chrome sends them: the absolute URL in the request line and Proxy-Connection in place of Connection. Credentials go in Proxy-Authorization: Basic from the first request, where Chrome waits for a 407; in exact header mode, an http:// request carries the Proxy-Authorization of its own fields only.

socks5:// sends the name, as Chrome, and socks4:// is taken as SOCKS4a, where Chrome resolves the name itself. Without credentials, the SOCKS5 greeting is Chrome's; with them, it also offers user/password (RFC 1929), which Chrome does not support. SOCKS4 sends the user as its user ID and has no password. With WithDialContext, that function opens the connection to the proxy.

The proxy chooses its exit when a connection opens: connections are reused as Chrome reuses them, every request of an origin over HTTP/2 going through one, unless WithNewConnectionPerRequest. Errors of the proxy wrap ErrProxy, or ErrProxyAuth for credentials, a 407 included.

Example

Through a proxy, every connection goes over it; the proxy resolves the destination. With WithNewConnectionPerRequest, each request opens its own connection, so a rotating proxy can give it another exit.

package main

import (
	"log"

	eidolon "github.com/acomerlatto/eidolon-tls"
)

func main() {
	c, err := eidolon.New(
		eidolon.WithProfile(eidolon.Chrome156Linux()),
		eidolon.WithProxy("http://user:password@proxy.example:8080"),
		eidolon.WithNewConnectionPerRequest(),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	resp, err := c.Get("https://example.com/")
	if err != nil {
		log.Fatal(err)
	}
	resp.Body.Close()
}

func WithRootCAs

func WithRootCAs(pool *x509.CertPool) Option

WithRootCAs sets the certificate authorities trusted for server certificates. The pool is copied when WithRootCAs is called. Without it, the system roots are used.

func WithStrictTLS12

func WithStrictTLS12() Option

WithStrictTLS12 refuses a TLS 1.2 connection, after its handshake and before any HTTP byte, whose cipher suite lacks ECDHE or AEAD, or whose server lacks extended master secret or secure renegotiation (RFC 9325), with an error that wraps ErrTLS12Policy. By default these are accepted, as Chrome does. The ClientHello does not change.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout limits the whole request, including reading the body, as http.Client.Timeout does. Zero means no limit. It applies to the client's own methods, not to an http.Client built on Transport().

type Order

type Order struct {
	// Pseudo orders the HTTP/2 pseudo-headers (":method", ":authority",
	// ":scheme", ":path"). Those not listed follow in Chrome's order,
	// ":method", ":authority", ":scheme", ":path".
	Pseudo []string
	// Header orders the regular headers. Names not listed follow in
	// alphabetical order; nil sorts them all alphabetically.
	Header []string
}

Order lists header names in the order they are sent, in both HTTP/2 and HTTP/1.1. Names are compared case-insensitively; a name listed twice keeps its first position, and a listed name without a value in the request creates nothing.

The order of a request (HeaderOrderKey, PHeaderOrderKey) comes first; the names of the client order (WithDefaultOrder) not listed yet follow, then the others in alphabetical order. Each list falls back the same way on its own: a request without PHeaderOrderKey uses the client's pseudo-header order.

type Profile

type Profile struct {
	// Name identifies the profile, such as "chrome/156/linux".
	Name string
	// ClientHello returns a new ClientHello spec for each connection, as
	// WithClientHello. Without it, WithClientHello is required.
	ClientHello func() (*utls.ClientHelloSpec, error)
	// HTTP2 is what a new HTTP/2 connection sends, as WithHTTP2Settings,
	// taken as given and validated the same way: its Settings need
	// ENABLE_PUSH 0, so its zero value is refused.
	HTTP2 HTTP2Settings
	// PseudoOrder orders the HTTP/2 pseudo-headers, as Order.Pseudo.
	PseudoOrder []string
	// Headers are added to every https:// request and InsecureHeaders to
	// every http:// one: what the browser sends whatever the request,
	// such as User-Agent, the client hints, Accept-Encoding and
	// Accept-Language. A field of the request's Header takes the place of
	// the profile's of the same name, and a name set to nil removes it.
	// Exact mode (WithExactHeaders) sends none of the profile's headers.
	// A profile with no Headers, InsecureHeaders or Dests adds no header.
	Headers, InsecureHeaders []HeaderField
	// Dests holds the headers of each destination (WithFetchDest). Over
	// https:// a request also sends Sec-Fetch-Site, Sec-Fetch-Mode and
	// Sec-Fetch-Dest. Sec-Fetch-Site compares the initiator, the origin of
	// the Referer of the first request of a redirect chain, with each URL
	// of the chain, by origin and by site (scheme and registrable domain,
	// by the public suffix list), and sends the furthest; without a
	// Referer, a navigation sends "none" and another request counts as
	// from its own origin. Origin is sent, over https:// and http://, by
	// a method other than GET and HEAD and by a cors request to another
	// origin, as the Fetch standard says, "null" after a redirect across
	// origins. A destination not listed gets Accept */*, no
	// Priority and the Sec-Fetch-Mode the Fetch standard gives it; an
	// iframe or frame gets those of FetchDocument, without
	// Sec-Fetch-User.
	Dests map[FetchDest]DestHeaders
	// NavigationOrder orders the headers of a navigation and
	// SubresourceOrder those of the other requests, as Order.Header:
	// names the request brings, such as Referer, Cookie or Content-Type,
	// take their place there too. Over HTTP/1.1, Host and Connection go
	// where they are listed.
	NavigationOrder, SubresourceOrder []string
	// H1Connection is sent in Connection over HTTP/1.1 unless the request
	// sets one; "" sends none.
	H1Connection string
	// H1Spelling spells header names over HTTP/1.1, as
	// WithHeaderSpelling; names not listed are sent in canonical form.
	H1Spelling []string
	// MaxConnsPerHost and IdleConnTimeout are those of WithMaxConnsPerHost
	// and WithIdleConnTimeout; zero keeps the default.
	MaxConnsPerHost int
	IdleConnTimeout time.Duration
}

Profile describes a browser in one version and platform: what its connections send and how it uses them. It is a plain value: derive one by copying a built-in profile and changing fields. WithProfile validates and copies it, so later changes do not reach a client.

Example

A custom profile starts from a built-in one. Here the ClientHello is rebuilt from a capture of the browser, with its extensions shuffled on each connection as Chrome does, and the HTTP/2 settings come from an Akamai fingerprint.

package main

import (
	"log"
	"os"

	eidolon "github.com/acomerlatto/eidolon-tls"
)

func main() {
	raw, err := os.ReadFile("testdata/chrome156-linux-clienthello.bin")
	if err != nil {
		log.Fatal(err)
	}
	hello, err := eidolon.ClientHelloFromRaw(raw, eidolon.WithShuffledExtensions())
	if err != nil {
		log.Fatal(err)
	}

	p := eidolon.Chrome156Linux()
	p.Name = "chrome/156/linux-captured"
	p.ClientHello = hello
	p.HTTP2, p.PseudoOrder, err = eidolon.ParseAkamai("1:65536;2:0;4:6291456;6:262144|15663105|0|m,a,s,p", p.HTTP2)
	if err != nil {
		log.Fatal(err)
	}

	c, err := eidolon.New(eidolon.WithProfile(p))
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()
	resp, err := c.Get("https://example.com/")
	if err != nil {
		log.Fatal(err)
	}
	resp.Body.Close()
}

func Chrome156Linux

func Chrome156Linux() Profile

Chrome156Linux returns the profile of Chrome 156.0.8078.73 on Linux, as captured on 28/10/2026: the ClientHello of the uTLS fork's HelloChrome_155, whose extensions are shuffled on each connection, with pre_shared_key at the end when it resumes a session, the HTTP/2 SETTINGS, WINDOW_UPDATE and priority of Chrome, the pseudo-header order :method, :authority, :scheme, :path, the headers of a navigation, a fetch() and a stylesheet, image or script, over https:// and http://, the client hints in lowercase and Connection: keep-alive over HTTP/1.1, and 6 connections per host. Each call returns a new copy. Over TLS 1.2, the server may renegotiate any number of times over HTTP/1.1, and never over HTTP/2.

Some positions of NavigationOrder were not captured: Content-Length, Cache-Control, Origin and Content-Type, which a form submitted sends. The image priority is that of an image in the page; Chrome sends the favicon at u=1, i.

type Protocol

type Protocol int

Protocol is an HTTP version the client may use.

const (
	HTTP1 Protocol = iota + 1
	HTTP2
	// HTTP3 is accepted and has no effect yet: the client never uses QUIC,
	// and an Alt-Svc header that announces h3 changes nothing.
	HTTP3
)

func (Protocol) String

func (p Protocol) String() string

Directories

Path Synopsis
internal
browser
Package browser adds the headers of a browser profile to a request: by context (https:// or http://) and by destination (internal/fetch), in the order of a navigation or of a subresource.
Package browser adds the headers of a browser profile to a request: by context (https:// or http://) and by destination (internal/fetch), in the order of a navigation or of a subresource.
cmd/labcapture command
Command labcapture records what a real browser sends, for the profiles of M2.
Command labcapture records what a real browser sends, for the profiles of M2.
dispatch
Package dispatch is the single entry point to the HTTP engines: it dials, reads the protocol negotiated by ALPN and hands the connection to the HTTP/2 or the HTTP/1.1 engine.
Package dispatch is the single entry point to the HTTP engines: it dials, reads the protocol negotiated by ALPN and hands the connection to the HTTP/2 or the HTTP/1.1 engine.
dns
Package dns queries the HTTPS records (RFC 9460) of origins and reads them as Chrome 156 does (net/dns): the query is Chrome's DnsQuery and the answer is read as its DnsResponse and ExtractHttpsResults read it.
Package dns queries the HTTPS records (RFC 9460) of origins and reads them as Chrome 156 does (net/dns): the query is Chrome's DnsQuery and the answer is read as its DnsResponse and ExtractHttpsResults read it.
fetch
Package fetch tells what a browser would fetch a request for: its destination in the Fetch standard, sent in Sec-Fetch-Dest.
Package fetch tells what a browser would fetch a request for: its destination in the Fetch standard, sent in Sec-Fetch-Dest.
fingerprint
Package fingerprint reads a ClientHello and computes its JA4 fingerprint, which the tests compare with a capture.
Package fingerprint reads a ClientHello and computes its JA4 fingerprint, which the tests compare with a capture.
gate
Package gate contains an alternative condition variable.
Package gate contains an alternative condition variable.
http1
Package http1 is the HTTP/1.1 engine.
Package http1 is the HTTP/1.1 engine.
http2
Package http2 implements the HTTP/2 protocol.
Package http2 implements the HTTP/2 protocol.
http2/hpack
Package hpack implements HPACK, a compression format for efficiently representing HTTP header fields in the context of HTTP/2.
Package hpack implements HPACK, a compression format for efficiently representing HTTP header fields in the context of HTTP/2.
httpsfv
Package httpsfv provides functionality for dealing with HTTP Structured Field Values.
Package httpsfv provides functionality for dealing with HTTP Structured Field Values.
lab
Package lab is a local server for fidelity tests.
Package lab is a local server for fidelity tests.
order
Package order computes the order of header fields, shared by the HTTP/2 and HTTP/1.1 engines.
Package order computes the order of header fields, shared by the HTTP/2 and HTTP/1.1 engines.
proxy
Package proxy opens tunnels through a proxy as Chrome 156 does, with the deviations a crawler needs: credentials from the URL and the name of the destination always resolved by the proxy.
Package proxy opens tunnels through a proxy as Chrome 156 does, with the deviations a crawler needs: credentials from the URL and the name of the destination always resolved by the proxy.
target
Package target normalizes the destination of a request into one identity shared by the dialer, the TLS verification and the HTTP engines.
Package target normalizes the destination of a request into one identity shared by the dialer, the TLS verification and the HTTP engines.
testcert
Package testcert contains a test-only localhost certificate.
Package testcert contains a test-only localhost certificate.
tlsdial
Package tlsdial opens TLS connections with a uTLS ClientHello spec.
Package tlsdial opens TLS connections with a uTLS ClientHello spec.

Jump to

Keyboard shortcuts

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