How 0x676e67/rnet works
Purpose and Entry Points
wreq is a Python-native HTTP client implemented by a Rust extension, targeting high-fidelity TLS, HTTP/2, and browser/device protocol emulation. Public Python imports and API façades live in python/wreq/__init__.py and modules such as python/wreq/wreq.py and python/wreq/blocking.py. The Rust extension is rooted at src/lib.rs; packaging/build integration is defined by pyproject.toml and Cargo.toml.
Python API Layer
The package exposes asynchronous and blocking clients, request/response types, and configuration domains (cookies, DNS, proxy, TLS, redirects, headers, HTTP/1 and HTTP/2). Python modules are likely thin bindings around Rust-exported types rather than an independent transport implementation.
Paths: python/wreq/wreq.py, python/wreq/blocking.py, python/wreq/http2.py.
Client Request Pipeline
The central client subsystem constructs requests, applies parameters/query/body encoding, dispatches network work, and exposes typed responses. Request bodies support plain streams plus form, JSON, and multipart formats; response handling includes HTTP payloads, extension methods, and WebSocket upgrades.
Paths: src/client.rs, src/client/req.rs, src/client/body/, src/client/resp.rs.
Transport and Protocol Boundary
HTTP protocol behavior is separated into core HTTP abstractions and explicit HTTP/1 and HTTP/2 modules. This is the boundary where protocol signatures/settings and connection behavior are material, including pooling, transfer streaming, trailers, decompression, and WebSocket response paths.
Paths: src/http.rs, src/http1.rs, src/http2.rs.
Identity, TLS, and Emulation
High-fidelity client identity is an architectural focus: emulation profiles configure browser-like TLS and HTTP/2 behavior rather than merely replaying JA3/JA4 strings. TLS integrates BoringSSL, supports certificate authorities, mutual TLS identities, certificate stores, and key logging.
Paths: src/emulate.rs, src/tls.rs, src/tls/identity.rs, src/tls/store.rs.
Stateful Request Policy
Cross-request state and routing policies are modular: cookie storage, redirect handling, proxy selection/rotation, DNS behavior, header preservation/control, and errors are distinct subsystems consumed by the client pipeline.
Paths: src/cookie.rs, src/redirect.rs, src/proxy.rs, src/dns.rs, src/header.rs.
Runtime, Concurrency, and Delivery
Async usage is designed for Python asyncio; a separate blocking client provides synchronous access. Rust-side no-GIL support indicates compatibility with Python free-threaded execution. Builds produce Python wheels through Maturin, require Rust plus BoringSSL tooling, and target Linux, macOS, Windows, and Android.
Paths: src/client/nogil.rs, pyproject.toml, Cargo.toml, .github/workflows/ci.yml.
Main entry points: client.rs Client orchestration · lib.rs Rust extension entry · tls.rs TLS integration · http.rs HTTP abstractions
Components 22
Python API
- Async API façade · Public asyncio-oriented client bindings.
python/wreq/wreq.py - Blocking API façade · Synchronous client access.
python/wreq/blocking.py - Python HTTP/2 API
python/wreq/http2.py
Rust Client Pipeline
- Rust extension entry · Exports Rust functionality to the Python package.
src/lib.rs - Client orchestration · Constructs and dispatches requests and exposes responses.
src/client.rs - Request construction · Applies parameters, query encoding, and request setup.
src/client/req.rs - Request bodies · Streams plain, form, JSON, and multipart payloads.
src/client/body.rs - Response handling · Handles payloads, extension methods, and WebSocket upgrades.
src/client/resp.rs
Protocol & Identity
- HTTP abstractions · Shared HTTP request, response, and connection abstractions.
src/http.rs - HTTP/1 transport · Supports streaming, trailers, and decompression behavior.
src/http1.rs - HTTP/2 transport · Applies HTTP/2 settings and connection behavior.
src/http2.rs - Browser emulation · Configures browser-like TLS and HTTP/2 behavior.
src/emulate.rs - TLS integration · Handles TLS, certificate authorities, mutual TLS, and key logging.
src/tls.rs - TLS identities
src/tls/identity.rs - Certificate store
src/tls/store.rs
Request Policy
- Cookie storage
src/cookie.rs - Redirects, proxy & DNS · Selects routes and governs redirect behavior.
src/proxy.rs - Header control · Preserves and controls request headers.
src/header.rs
Runtime & Delivery
- Free-threaded support · Supports no-GIL Python execution.
src/client/nogil.rs - Maturin packaging · Builds Rust extension wheels for supported platforms.
pyproject.toml - Rust & BoringSSL build · Defines Rust dependencies and native build integration.
Cargo.toml - Cross-platform CI · Builds and validates target platform artifacts.
.github/workflows/ci.yml
Connections 22
- Async API façade → Rust extension entry: calls
- Blocking API façade → Rust extension entry: calls
- Python HTTP/2 API → Rust extension entry: binds
- Rust extension entry → Client orchestration: exports
- Client orchestration → Request construction: builds
- Request construction → Request bodies: encodes
- Client orchestration → Response handling: returns
- Client orchestration → HTTP abstractions: dispatches through
- HTTP abstractions → HTTP/1 transport: selects
- HTTP abstractions → HTTP/2 transport: selects
- Browser emulation → HTTP/2 transport: configures
- Browser emulation → TLS integration: configures
- HTTP/1 transport → TLS integration: secures with
- HTTP/2 transport → TLS integration: secures with
- TLS integration → TLS identities: uses
- TLS integration → Certificate store: reads
- Client orchestration → Cookie storage: maintains
- Client orchestration → Redirects, proxy & DNS: applies
- Client orchestration → Header control: applies
- Rust extension entry → Free-threaded support: supports
- Maturin packaging → Rust & BoringSSL build: builds
- Cross-platform CI → Maturin packaging: produces wheels