Repository navigation
lkrequest-py v0.2.1
Adds the Chrome 152 preset and browser network session policies, and picks up a
large upstream RFC-compliance pass. Several fixes below change observable
behaviour — the ECH, retry, redirect, cookie and connection-limit entries are
the ones most likely to affect existing code.
🚀 Features
- Chrome 152 Preset — Added
Client.chrome_152(),BlockingClient.chrome_152(),TlsProfile.chrome_152(),TlsProfile.chrome_152_quic(),H2Profile.chrome_152(),QuicProfile.chrome_152(), and the"chrome_152"TLS/H2/QUIC profile names. Chrome 152 is currently the only preset that applies GREASE tosignature_algorithms, and it carries the new trust anchor IDs extension. HTTP/2 is unchanged from Chrome 151; the QUIC capture drops thegoogle_initial_rtttransport parameter (0x3127). - Browser Network Session Policies — Added
TlsSessionResumptionPolicy(BROWSER_DEFAULT/DISABLED/enabled(max_tickets_per_server)),TlsSessionCachePartitionPolicy(UNPARTITIONED/TOP_LEVEL_SITE/TOP_LEVEL_AND_FRAME_SITE/CHROMIUM/FIREFOX), andNetworkPartitionContext(top_level_site, frame_site). Set the first two viaClient(tls_session_resumption_policy=..., tls_session_cache_partition_policy=...)and pass the third tosession(network_partition_context=...)to reproduce a browser's per-site ticket isolation. These control whether tickets are stored and how the cache is keyed;SessionResumptionConfigcontinues to control which resumption modes the ClientHello advertises. - HTTP/2 DATA Frame Policy — Added
Client(h2_data_frame_policy=...)withH2DataFramePolicy.BROWSER_DEFAULT,.PEER_MAX_FRAME_SIZE,.fixed_payload(n), and.socket_write_aligned(n), choosing how request bodies are split into DATA frames. The default keeps the browser preset's native framing, since frame sizes are themselves an observable fingerprint trait. - Strict TLS close_notify — Added
Client(require_close_notify=True)and a matching read-only property. When enabled, a response body truncated by a bare socket EOF — with no TLSclose_notifyalert — is reported as an error instead of being accepted as a complete body. One part applies regardless of the flag: the read loop now stops atclose_notifyinstead of reading on, because anything arriving after it did not come from the peer — those bytes were previously appended to the response body. - Trust Anchor IDs Extension — Added
ExtType.TRUST_ANCHOR_IDSand a newExtensionSpecsource:ExtensionSpec(ExtType.TRUST_ANCHOR_IDS, source="trust_anchor_ids", trust_anchor_ids=[...], shuffle=False), withtrust_anchor_idsandshufflereadable back off the spec. - DNS-over-HTTPS Feature — Upstream moved the DoH resolvers behind a
dohCargo feature. The published wheels enable it, sodns="google_https","cloudflare_https"and"quad9_https"keep working exactly as before; a reduced-feature source build now rejects those three names with an actionable error instead of a generic "unknown DNS config".
🐞 Fixes
- A Rejected ECH No Longer Falls Through In The Clear — when a server did not accept Encrypted ClientHello, the handshake previously carried on and handed back a connection whose real server name had never been protected, so the request ECH existed to hide went out in the open. The handshake now aborts before any traffic keys exist, and the session redials once with the
retry_configsthe server supplied — the same thing a browser does, so routine ECH key rotation stays transparent. Retrying without ECH is deliberately not a fallback. This affects clients that never setech_config=, because ECH is enabled automatically from DNS HTTPS records; a rejection that cannot be retried now surfaces asTlsError. GREASE ECH is unaffected. - Status-Code Retries Are Gated On Replay Safety — a non-idempotent request answered with a status in the retry set was replayed even though the answer proves the server received it, so a
POSTanswered502was sent twice. Such a method is now retried only on a status that says it was not applied (429,503);502,504and the Cloudflare520–530range are returned to the caller instead. Safe methods are unaffected, and passingidempotency=Idempotency.Idempotenton the request restores the old behaviour per call. - Only Real Redirect Statuses Are Followed —
300,304,305and306are no longer treated as redirects. Previously a304 Not Modifiedor a305 Use Proxycould send the client chasing aLocationheader it should have ignored.301,302,303,307and308are unaffected. - Cookie Name Prefixes Enforced — Cookies named with the
__Secure-or__Host-prefix are now rejected unless they satisfy the prefix rules (Secure, and for__Host-also a/path with noDomain). A server can no longer set a lookalike cookie that client code would reasonably trust. - Secure Cookies Ignored Over Plain HTTP — A
Set-CookiecarryingSecurereceived over a plain-HTTP channel is now discarded rather than stored. - Sessions Are No Longer Capped At 64 Connections — The implicit per-session ceiling made unrelated high-concurrency workloads fail with
session connection limit reached. The default is now unbounded; setmax_connections_per_sessionexplicitly to impose a budget. - Multi-Layer Content-Encoding Is Decoded — A response carrying stacked encodings (for example
Content-Encoding: gzip, br) is now fully decoded instead of being returned partly compressed. The zlib-wrapped form ofdeflateis also accepted, matching what browsers tolerate. - WebSocket Handshakes And Close Codes Are Validated — the upgrade response was checked only for a
101, which on its own proves nothing; a wrong or missingSec-WebSocket-Acceptmerely logged a warning. RFC 6455 §4.1 makes that, a missing or wrongUpgrade/Connection, and any unoffered extension or subprotocol grounds for failing the connection, and all are enforced now. Enforcing it also uncovered thatSec-WebSocket-Acceptwas being computed with a GUID that is not the one §1.3 specifies, so the token never matched a conforming server — harmless while the check only warned. On the sending side,1005,1006and1015may never appear on the wire (§7.4.1) and are now rejected locally, along with over-long close reasons, instead of producing an invalid frame. - HSTS Is Learned Only From Secure Transport —
Strict-Transport-Securityis no longer recorded from a plain-HTTP response, and never for IP-literal hosts. - Multipart Bodies Match Chrome — Boundary generation and parameter escaping now follow Chrome's format. A
Content-Typecontaining CR or LF is rejected outright, since — unlike the quotedContent-Dispositionparameters, which are escaped — it cannot be encoded safely and would be a live header-injection vector. - Redirect Method Rewriting Follows The Spec — The request method is now rewritten only in the cases the specification calls for, so
307and308correctly preserve the original method and body. - Graceful HTTP/2 GOAWAY Is Honoured — a graceful shutdown carries
NO_ERRORand therefore set no connection error, while the draining check keyed off "has an error". The driver kept opening streams on a connection the peer had already promised to refuse. Google and Cloudflare send these routinely for connection turnover, so this showed up as sporadic failures under sustained load; queued requests now fail over to a fresh connection. - Alternative Services No Longer Supply The TLS Identity — an Alt-Svc entry or DNS HTTPS record says where to send packets, but the endpoint must still prove it may serve the origin. The advertised host was used as the SNI and certificate name, so the alternative authenticated as itself. Besides the trust problem this broke conforming deployments outright, since an HTTPS RR
TargetNameis typically a CDN-internal name serving the origin's certificate. - Certificates Compressed With zstd Decompress —
compress_certificateadvertises zlib, brotli and zstd (the Firefox 147 profile offers all three), but only zlib and brotli could be decoded, so a server that picked zstd failed the handshake. All three are handled now (RFC 8879). - Coalesced TLS Post-Handshake Messages Are Reassembled — post-handshake messages follow the same framing as the handshake: several may share one record, and one may span several. Each record was treated as exactly one message, so a
KeyUpdatesharing a record with aNewSessionTicketwas silently dropped — read keys were never rotated and every record after it failed to decrypt — and coalesced tickets past the first were lost. - Protocol Hardening Across TLS, HTTP/2, QUIC And Alt-Svc — Picks up a broad upstream compliance pass: TLS 1.2 renegotiation is refused with a fatal alert, the record layer and session-ticket trust are bounded, servers can no longer select parameters the client never offered, HTTP/2 enforces response pseudo-header rules and closes connections on peer protocol errors,
record_size_limitis honoured when sending (RFC 8449), draft HTTP/3 Alt-Svc advertisements are ignored, and SOCKS5 authentication replies are version-checked.