Skip to content

lkrequest-go v0.2.4

Choose a tag to compare

@ezxlabs-admin ezxlabs-admin released this 19 Oct 04:54
· 2 commits to main since this release

Updates the bundled lkrequest-ffi native engine, adds the Chrome 155 preset
and makes it the default, reads session cookies with their attributes, and lets
a request set its HTTP/2 priority weight. Every addition is new API — the native
surface grew by three symbols and changed none — so every existing call shape
keeps working.

Most fixes reach code you have already written: a site that advertises HTTP/3
on a network that drops UDP no longer fails every request, a redirect to
another origin no longer carries the client's default Authorization along,
and HTTP/2 requests that were given up on are reset instead of holding their
stream open. Three entries change behaviour you may be relying on and are worth
reading before upgrading: the default preset, the HTTP/2 frames of the Chrome
and Firefox 156 presets, and proxy pools, which now wait for a proxy instead of
handing out a direct connection.

🚀 Features

  • Chrome 155 Preset — SetPreset("chrome_155") / NewClient("chrome_155"), captured from Chrome 155.0.8059.40 (Windows, October 2026). Every layer keeps Chrome 154's shape: TCP TLS with its 28 trust-anchor identifiers, HTTP/2, QUIC TLS, QUIC transport parameters, Initial packetization and HTTP/3 SETTINGS — the last now observed directly on a successful HTTP/3 response rather than inherited. What sets it apart is how its QUIC connections behave once established: it adopts Chrome 155's HTTP/3 request handling, including a PRIORITY_UPDATE sent for each request stream before its HEADERS, and its loss-recovery and packetization timing.
  • Cookie Attributes — Session.GetCookiesWithAttrs(url) and Session.GetAllCookies() return []CookieInfo: name and value together with Domain, HostOnly, Path, Secure, HTTPOnly, SameSite and ExpiresUnix (nil for a session cookie; IsPersistent() says which). GetCookies returns name/value pairs, so two cookies sharing a name at different paths came back as two indistinguishable entries; here Path tells them apart, longest path first. GetCookiesWithAttrs is scoped to a URL like GetCookies; GetAllCookies spans every domain, oldest first, and is the view to persist or hand to a browser automation context. Reading only — SetCookieWithAttrs still cannot set SameSite or an expiry. Cookie is unchanged.
  • Per-Request HTTP/2 Priority Weight — Request.SetH2PriorityWeight(weight) sets the weight in the legacy priority field of the request's HTTP/2 HEADERS frame as it goes on the wire: 0–255, one less than the 1–256 weight it encodes. It is for a request a browser weighs differently from what the preset sends by default. It applies whether the request opens a connection or reuses one, buffered or streaming; it leaves the priority header, the stream dependency and the exclusive flag alone; and it holds for that request only, though Clone() carries it over. A preset whose HEADERS carry no legacy priority field still sends none, and HTTP/1.1 and HTTP/3 ignore it.

🐞 Fixes

  • Cookie Calls on a Shared Session — the library hands cookie readers a buffer it frees as soon as a cookie is set, removed or cleared, or the same query runs again. GetCookie and GetCookies / GetCookiesJSON copied that buffer without synchronizing with those calls, so on a Session shared across goroutines — which is documented as safe — a read racing a write could return a corrupted value instead of the cookie. Cookie reads and writes on one Session are now serialized; a Clone() has its own buffers and is not affected by its original.
  • Arguments Read From a Moved Goroutine Stack — strings shorter than 32 bytes (URLs, header and cookie names and values, preset names, ...), and small byte slices or arrays handed to the library, could be left on the calling goroutine's stack and passed by address. Go moves a stack when it grows or when the GC shrinks it, so the library could read the old, freed stack instead of the argument. With the default purego engine the call then failed or, worse, succeeded on the wrong value — a cookie stored under a corrupted name, for instance; with lkcgo the process aborted with fatal error: found bad pointer in Go heap. It took a stack move inside a narrow window, so it showed up mostly under heavy concurrency and GC load, but nothing ruled it out. Every buffer passed to the library is now heap allocated, where it does not move.
  • A QUIC Handshake That Times Out Falls Back to TCP — once a site had advertised HTTP/3 through Alt-Svc, a request on a network that silently drops UDP waited out the QUIC handshake timeout and then failed with it, instead of falling back to TCP as it does when the handshake fails any other way — and every request after it did the same. Buffered and streaming requests now fall back to HTTP/2 or HTTP/1.1.
  • Redirects No Longer Carry Default Credentials to Another Origin — headers added with ClientBuilder.AddDefaultHeader were applied again on every hop of a redirect chain, so a default Authorization, Cookie or Host went along to the destination of a redirect to another origin, although the same headers set on the request itself were dropped there. Defaults are now filtered hop by hop the way a request's own headers are: a redirect that leaves the origin (scheme, host or port) drops a default Authorization, Cookie and Host; one from https to http drops a default Referer; one that turns a POST into a GET drops the default Content-Type, Content-Encoding, Content-Language, Content-Location and Content-Length. The client's defaults are untouched for the next request.
  • A Location in Raw UTF-8 Is Followed — a redirect whose Location held raw UTF-8 bytes (/café) was reported as missing its Location and failed. The value is now decoded, resolved against the current URL and percent-encoded on the way out, as a percent-encoded one is; one that is not valid UTF-8 is an error that says so.
  • An Empty Max-Age in Set-Cookie Is Ignored — Set-Cookie: sid=abc; Max-Age= was read as a Max-Age too large to represent, so the cookie was kept until the year 9999 instead of as a session cookie; and because Max-Age outranks Expires, a response that deleted a cookie with Max-Age=; Expires=<a past date> left it in place. An empty Max-Age now counts as absent, and a valid one given before it still applies.
  • Truncated and Look-Alike deflate Bodies — a deflate body that ended before its stream did came back shorter without an error, buffered or streaming; it is now an error. A raw deflate stream, which some servers send in place of the zlib format the name stands for, was rejected as corrupt when its first bytes happened to read as a zlib header; it is now accepted.
  • Abandoned HTTP/2 Requests Are Reset — a request given up on after it was sent — a timeout, a cancelled context, a streaming response closed early — was never reset with RST_STREAM, so its stream stayed open on the server for as long as the connection lived. On a shared Session that could use up the server's concurrent-stream limit, after which further requests queued without being sent and timed out. Such a request is now reset with CANCEL and its stream freed. HTTP/1.1 was not affected.
  • Requests the Server Never Processed Are Replayed — a request that an HTTP/2 GOAWAY cut off before any response headers arrived, or that HTTP/3 refused with H3_REQUEST_REJECTED before them, never reached the server's processing, and is now treated as safe to replay automatically.
  • Reused HTTP/1.1 Connections Reset by the Server — a request sent on a pooled HTTP/1.1 connection that the server had reset failed with an HTTP error, so SetRetryOnConnectionClose, which is on by default, did not apply. The reset now counts as the connection closing: a request that is safe to replay is retried on a new connection, and a POST still fails.
  • SetTimeoutDNS Bounds Every Lookup — the DNS timeout is now a deadline for each query the client makes, address and HTTPS-record lookups alike, through the built-in resolver ahead of its own retries or through a SetDNSResolver callback. A request that runs into it fails as a timeout in the DNS phase.
  • The First Request on a New HTTP/2 Connection Gets Its Priority — the request that opens a connection now resolves its priority from the same request and client headers, and the same fetch-destination rules, as a request on a reused connection, so a navigation keeps its navigation priority on a fresh connection too.
  • A Proxy's Refusal After the Authentication Retry Keeps Its Status — when a proxy answered CONNECT with 407 and then refused the retry that carried credentials, the error always said authentication had failed, even for a 503. A second 407 is still reported that way; any other status is now reported as the tunnel being refused, with that status.
  • TLS, ECH and QUIC Handshake Corrections — a broad upstream pass over handshake behaviour, much of it visible on the wire. The client now refuses, with the alert Chromium or NSS sends, a server hello a browser would refuse — a version, cipher suite, compression method or ALPN protocol it never offered, a malformed or padded extension, a wrong session-ID echo, a fallback to TLS 1.2 after a HelloRetryRequest — before deriving any key. A TLS 1.3 handshake queues its compatibility ChangeCipherSpec until the client's final flight, as Chromium and NSS do. After a HelloRetryRequest the client drops pre-shared keys whose hash no longer matches, keeps the first ClientHello's trust-anchor order, and carries the cookie into a real ECH handshake's inner ClientHello. ECH rejection is handled across HelloRetryRequest and TLS 1.2, and over QUIC as CRYPTO_ERROR(ech_required). ECH GREASE is generated as each browser generates it: an X25519 key pair for the enc field on Chromium, and Firefox's per-handshake choice between AES-128-GCM and ChaCha20-Poly1305.

⚠️ Behaviour Changes

  • The Default Preset Is Now Chrome 155 — NewDefaultClient(), a ClientBuilder built without SetPreset, and NewClient("default") now resolve to the complete chrome_155 preset instead of chrome_144. The package-level helpers (Get, PostJSON, ...) run on NewDefaultClient(), so they change too. Every request made without an explicit preset now presents a Chrome 155 fingerprint. To keep the previous one, ask for it by name: NewClient("chrome_144") or SetPreset("chrome_144").
  • Proxy Pools Wait Instead of Connecting Directly — when every proxy of a pool was cooling down or removed, ProxyPool.Acquire answered with a lease that carried no proxy — its URL() was "" — which a caller takes for a direct connection, exposing its own address; a SessionPool then built a session without a proxy. A pool with proxies no longer does: Acquire waits for a cooling proxy to recover, and once every proxy is removed for good, it waits forever. Bound the wait with AcquireAsync(ctx); giving up frees the permit the acquisition held. Only a pool built without any proxy hands out direct leases. Alongside, ProxyPool.MarkBad takes effect before it returns rather than shortly after, and closing the guard of a session marked with SessionPool.MarkBad discards that session instead of returning it to the idle pool.
  • HTTP/2 Frames of the Chrome and Firefox 156 Presets — visible on the wire. Firefox 156 now opens its first request on stream 3, as its capture shows, instead of 1, and sends navigation HEADERS with wire weight 41 where it sent 42. The Chrome presets now make each stream depend on the newest still-active stream of equal or higher priority, dropping finished and reset streams, instead of on the stream opened just before it.