Leyline user guide
Leyline is an HTTP client that mimics browsers on the wire. This guide shows you how to use it, in reading order.
Leyline has two kinds of session:
| You want | Call | What the server sees |
|---|---|---|
| Plain HTTP | leyline::get(url) or Session::new() | A plain client with a leyline/<version> user agent. |
| Look like a browser | Session::browser(Browser::default()) or Session::builder().browser(Browser::Chrome154) | The TLS, HTTP/2, and headers of a captured browser. |
Session::browser(Browser::default()) impersonates the newest bundled Chrome
on Windows. Session::new() and a builder with no browser build a plain client.
- Quick start: add the dependency, send your first request.
- Sessions: pick a browser, a platform, and a brand.
- Choosing a profile: which browser and platform to claim.
- Requests: methods, headers, bodies, presets, tabs, and downloads.
- Responses: status, headers,
Linkpagination, block detection, bodies, timing, audit. - Streaming: stream a body in either direction, download a file, or stop a read early.
- Redirects: the redirect limit and custom redirect policies.
- Retries and timeouts: retry policies and the four timeouts.
- Errors: group errors by category, map them to statuses, and find out which errors a retry covers.
- Proxies: proxy rules, bypass lists, environment discovery.
- Cookies: the jar, saving it, devices, and connection state.
- WebSocket: connect over HTTP/2 or HTTP/1.1.
- HTTP/3: the
http3feature and the protocol policy. - TLS trust: roots, certificate pins, client certificates, the TLS version floor.
- Network: DNS overrides, Happy Eyeballs, socket options.
- Logging and tracing:
tracingtargets and request phases. - Fingerprints: what a profile pins and how to audit it.
- Features and targets: cargo features, targets, MSRV.
- Supported platforms: the six build targets and the tools each one needs.
- Cancellation: what happens when you drop a request or a body.
- Testing: local plain and TLS servers, and asserting what was sent.
- Service integration: Tower, shared sessions, and error mapping in a server.
- Crawling: host limits, proxy pools, block detection, and tags.
- Accounts: tabs, saved devices, and the state of a returning browser.
Reference pages beside this guide: profiles and MSRV.
The Rust blocks in these pages are doctests of the leyline-http crate. The
Tower block in Requests compiles only with the tower
feature. A plain cargo test does not enable it. The pull-request check in CI
runs cargo test with
--features leyline-http/full,leyline-http/bench-internals, which does. The
toml, sh, and js blocks are not compiled. Blocks that open a socket are
marked no_run, so they compile but do not send traffic.