Repository navigation
Releases
Releases · EZXLabs/lkrequest-js
lkrequest-js v0.1.0
The first release of lkrequest-js, the Node.js binding of lkrequest 0.3.0, a Rust HTTP client.
It reproduces the TLS handshake, HTTP/2 settings, HTTP/3 and QUIC parameters and TCP options of
a real browser, or sends a fingerprint you build yourself, behind a fetch-style API with
sessions, cookies, proxies, WebSocket and typed errors. Requests run on a Rust async runtime, so
they do not block the event loop. It needs Node.js 22.12 or later and is an ES module package
that CommonJS code can load with import() or require(). TypeScript types are included, and
prebuilt addons cover Linux (glibc 2.28 or later, and musl), macOS and Windows, on x64 and arm64.
🚀 Features
- Browser Presets —
presettakes one of 21 browser fingerprints: Chrome 131 and 144–158,
Firefox 133, 147 and 156, and Safari 18 and 26. Each sets the TLS handshake, the HTTP/2
settings and the TCP fingerprint together, and the Chrome presets add HTTP/3 and QUIC;
listPresets()names them. A client without a preset presents Chrome 155's TLS and HTTP/2,
with HTTP/3 off.PresetBundleexports a preset as lkrequest's preset JSON and reads one back,
edited or of your own, forpresetto take in place of a name; a bundle carries no TCP
fingerprint, so givetcpFingerprintwith it.features()andversionreport the compiled
capabilities and the version. - Clients And Sessions — A
Clientholds the fingerprint and the connection settings:
default headers, header and cookie order, HTTP/1.1 header case (h1.titleCaseHeaders), phase
timeouts (timeouts, among themreadIdlefor a body that stops arriving;nullturns one
off), resource limits, HTTP/2 dispatch batching and fallbacks (all off by default). Its
sessions each keep their own cookies, connection pool, redirect mode (follow,manualor
error, withmaxRedirects),baseUrl, retries, middleware and hooks, and sendget,
post,put,delete,head,patch,optionsandrequest.client.get()and the other
methods use a session of their own, closed afterwards.attemptLimits, on a client, a session
or a request, caps the retries and recoveries of a request and the connections it starts.
preconnect(),preconnectMany()andprefetch()open connections ahead of the requests;
poolStats(),clearPool(),close()andSymbol.disposemanage them, and a request on a
closed session fails withERR_LK_SESSION_CLOSED. - Requests — Headers keep the order you give them, and a name repeated among the pairs is
sent once per value. The options coverparams,json,cookies,cookieOverride,auth,
timeout,decompressandacceptEncoding(gzip, Brotli, deflate and zstd), the RFC 9218
priority,h2PriorityWeight,idempotency, aproxyfor one request (refused when invalid
rather than ignored), andsignalto cancel with anAbortSignal. Bodies follow the Fetch
standard: strings, binary data,Blob,URLSearchParams,FormDatawith a Chrome-style
multipart boundary, and streams (ReadableStream,Readable, async iterables) pulled with
backpressure. - Responses — A
fetch-styleResponsewithstatus,ok,headersandredirected,
zero-copybytes(),arrayBuffer(),blob()andbody, charset-awaretext()andjson(),
and beyond fetch,headerList(duplicates kept),httpVersion,cookies,history,
diagnostics,attemptSummary(what the request did, also on its error when it fails),
elapsedandthrowForStatus().session.stream()returns aStreamingResponsewhose
decompressed body is pulled from the network as you read it, and released when cancelled,
disposed or garbage collected. Adeflatebody is decoded in zlib or raw form, and one cut
short fails rather than coming back shorter. - Redirects — A redirect filters the client's
defaultHeadersas it filters the request's
own headers: one to another origin drops a defaultAuthorization,CookieorHost, one
from https to http a defaultReferer, and one that turns a POST into a GET the default
Content-Type,Content-Encoding,Content-Language,Content-Locationand
Content-Length. ALocationwritten in raw UTF-8 is followed, percent-encoded. - Cookies —
session.cookiesis aCookieJarin the Playwright and Puppeteer cookie format,
which also takes rawSet-Cookievalues throughsetRaw(). An emptyMax-Agecounts as
absent, so a pastExpiresstill deletes the cookie. - Errors — Failures are
RequestErrorand its subclasses (ConnectionError,
TimeoutError,TlsError,ProxyError,HttpStatusError,TooManyRedirectsError,
ResourceLimitError), which carry acode(ERR_LK_*), upstream'skind, thephasethat
failed and theretryableandsafeToReplayhints. A cancelled request rejects with
AbortError, andjson()on a body that is not JSON withJsonDecodeError. - WebSocket —
session.websocket()opens a connection that keeps the session's fingerprint
and proxy, with handshakeheaders,protocols,extensions(permessage-deflatecompresses
the messages) andsignal. Cookies in the jar are not sent; pass acookieheader to send
some. TheWebSocketConnectionsends, receives, pings, pongs and closes, iterates
asynchronously and supportsSymbol.asyncDispose; a send or a close does not wait for a
pending receive. - Retries, Middleware And Hooks — The session's
retrytakes theexponentialorfixed
strategy, or a function, possibly async, that decides each retry from
{ attempt, error, status }.middlewareon the client and the session runsonRequestand
onResponseinterceptors in onion order, which may change the method, URL, headers, body and
status. TheonRequestandonResponseevent hooks observe each request and return an
unsubscribe function. - HTTP/2 And HTTP/3 —
preferredHttpVersionandhttpIntentper session or request, and
protocolPolicy: a preset, or an object that adjusts the policy in force axis by axis
(intent,acquisitionwith a TCP/QUICrace,upgrade,fallback) on the client, the
session or the request; contradictory combinations are refused. HTTP/3 comes with
brokenQuicPolicy(and its cooldowns),disableHttp3,timeouts.quicConnect,
h3HeaderOrder, andh3RetryMode: "chrome_155_protocol_errors", which retries HTTP/3
protocol errors as Chrome 155 does. An HTTP/2 request that is aborted, times out or has its
streamed body cancelled resets its stream, so it frees its slot on the connection. - Proxies —
ProxyConfigfor HTTP CONNECT, SOCKS5 and SOCKS5h proxies and multi-hop chains,
with a user name and password, a static HTTP credential (withHttpAuth, in the header
withAuthHeaderpicks) or one your code computes on every connection (withCustomAuth, for
one-time tokens, withonChallengeto answer a407challenge in a scheme such as Digest).
healthCheck()measures how long a tunnel takes to open. When a proxy refuses the retry after
a 407 challenge, theProxyErrornames the status it answered. A request falls back to a
direct connection only withfallback.proxyToDirect. - Pools —
ProxyPoolrotates proxies, cools bad ones down and checks their health, leasing
them withacquire()andacquireFresh()under amaxConcurrentlimit.SessionPoolleases
ready sessions (release(),Symbol.dispose, or returned when garbage collected), and
ClientPoolrotates clients round robin or at random.ProxyPoolandSessionPoolalso take
a function in place of the proxy list, withproxyBufferkeeping a few proxies ready. A pool
given proxies never leases without one: while every proxy cools down or the function fails,
acquire()waits, and takes asignalto give up. - DNS And Addresses —
dnstakes a preset (the system resolver, cached, public resolvers and
DNS over HTTPS),{ server }for a DNS server of your own, or{ resolve, lookupHttps? }for
your own functions, which may also return HTTPS records that make a request try HTTP/3.
dnsCachecaches the answers,family(0,4or6) limits the address family,
connectTopins the address dialled for a host, andtimeouts.dnslimits every DNS query,
whichever resolver answers it (5 seconds by default). - TLS And HSTS —
ca,caDer,rejectUnauthorized,useNativeCerts,echand
requireCloseNotify; session resumption (sessionResumption,tls.sessionResumptionPolicy),
its cache partitioned bytls.sessionCachePartitionPolicyand the session's
networkPartitionContext, withtls.sessionCacheTtlfor how long a session is kept; Trust
Anchor Identifiers over TCP and QUIC (tls.trustAnchorIds); andkeylogto a file or a
function, for Wireshark. HSTS policies (Hsts.none(),static(),dynamic()orcustom())
are shared between the sessions they are given to, next tohttpsOnly. - Fingerprint Profiles —
TlsProfile,H2Profile,TcpFingerprintandQuicProfile, from
a preset, built by hand or loaded from upstream's JSON format, override a preset's layers
(tlsProfile,h2Profile,tcpFingerprint,quicFingerprint,quicProfile).
TlsProfile.fromClientHello()andH2Profile.fromH2Frames()rebuild profiles from captured
traffic, andparseH3ControlStream()reads a captured HTTP/3 control stream.H2Profilesets
the first stream id and the stream dependency policy,TcpFingerprinttakes JA4T, TCP options
and keepalive,H2ProfileandQuicProfilevalidate themselves, and the 62-bit values of a
QuicProfilestay exact through JSON.randomizeshuffles the TLS extension order on every
connection or synthesizes whole fingerprints, andclient.fingerprintInfo(),
randomizeFingerprint()andvalidateFingerprintConsistency()inspect, vary and check them. - MASQUE (Experimental) —
masque://proxies (RFC 9298 CONNECT-...