rama/
lib.rs

1//! 🦙 **rama** (ラマ) is a modular network service and proxy framework for the 🦀 Rust language.
2//!
3//! It gives you programmable control over how packets move through your stack so you can build:
4//!
5//! - production grade reverse and forward proxies
6//! - HTTP and TLS termination layers
7//! - security inspection and distortion proxies
8//! - high volume scraping and data extraction pipelines
9//! - custom HTTP clients with deep control over the wire
10//!
11//! rama is already used in production by companies at scale for use cases such as network
12//! security, data extraction, API gateways and routing.
13//!
14//! rama is async first and uses [`tokio`](https://tokio.rs) as its only async runtime.
15//!
16//! ---
17//!
18//! ## Who is rama for
19//!
20//! - **Developers and teams** who want fine grained control over transport, TLS and HTTP
21//!   while staying in safe Rust.
22//! - **Organisations** that need a partner to:
23//!   - maintain and evolve a proxy or network platform
24//!   - build custom features on top of rama
25//!   - get support and training for internal teams
26//!
27//! ---
28//!
29//! ## Getting started
30//!
31//! 1. Read the ["Why rama" chapter](https://ramaproxy.org/book/why_rama) for background.
32//! 2. Run one of the examples in
33//!    <https://github.com/plabayo/rama/tree/main/examples>.
34//! 3. Use the rama book at <https://ramaproxy.org/book> and the Rust docs at
35//!    <https://docs.rs/rama> or <https://ramaproxy.org/docs/rama> as references
36//!    while building your own stack.
37//!
38//! You can also use the `rama` binary if you want to use some of the rama features from the command line
39//! without writing your own Rust code. See <https://ramaproxy.org/book/deploy/rama-cli.html>.
40//!
41//! ---
42//!
43//! ## Experimental status
44//!
45//! rama is considered experimental software for the foreseeable future. At the same time
46//! it is already used in production by the maintainers and by other organisations.
47//!
48//! Real world use helps shape the design and priorities. If you run rama in production,
49//! feedback via GitHub issues, email or Discord is very welcome.
50//!
51//! ---
52//!
53//! ## For organisations
54//!
55//! If your organisation relies on rama or plans to, the maintainers offer:
56//!
57//! - support and maintenance contracts
58//! - feature development with higher priority or extended scope
59//! - consulting and integration work around proxies, scraping and security
60//! - training and mentoring for your internal teams
61//!
62//! To discuss options, contact `hello@plabayo.tech`.
63//!
64//! Enterprise sponsorships are available via GitHub Sponsors and help fund development,
65//! maintenance and ecosystem work.
66//!
67//! ---
68//!
69//! ## Batteries included
70//!
71//! rama ships with batteries included for transports, HTTP, TLS, DNS, proxy protocols,
72//! telemetry, fingerprinting and more. Some highlights:
73//!
74//! - transports: TCP, UDP, Unix domain sockets, connection pooling and middleware
75//! - HTTP: HTTP 1 and 2 servers and clients, layers and middleware, metrics, tracing
76//! - TLS: Rustls and BoringSSL support
77//! - proxy protocols: HTTP connect, HTTPS connect, SOCKS5, HAProxy PROXY protocol
78//! - fingerprinting and user agent emulation for distortion and anti bot use cases
79//! - telemetry: tracing integration and OpenTelemetry metrics for HTTP and transport layers
80//!
81//! For a detailed and up to date overview see the feature table in the README and the
82//! relevant chapters in the rama book.
83//!
84//! ---
85//!
86//! ## Proxies and proxy focused use cases
87//!
88//! The primary focus of rama is to help you build proxies and proxy like services:
89//!
90//! - reverse proxies
91//! - TLS termination proxies
92//! - HTTP and HTTPS proxies
93//! - SOCKS5 proxies
94//! - SNI based routing proxies
95//! - MITM proxies
96//! - distortion proxies with UA emulation and fingerprinting
97//!
98//! The proxy chapters in the book start at
99//! <https://ramaproxy.org/book/proxies/intro.html>.
100//!
101//! Distortion support includes User Agent emulation for HTTP and TLS built on top of data
102//! collected by [`rama-fp`](https://github.com/plabayo/rama/tree/main/rama-fp) and exposed
103//! via <https://fp.ramaproxy.org>.
104//!
105//! ---
106//!
107//! ## Web services
108//!
109//! Even though proxies are the main focus, rama can also be used to build general purpose
110//! web services. Typical use cases:
111//!
112//! - dynamic HTTP endpoints
113//! - serving static files
114//! - websockets and Server Sent Events (SSE)
115//! - health and readiness endpoints for Kubernetes
116//! - metrics and control plane services
117//!
118//! rama gives you:
119//!
120//! - async method trait based services and layers
121//! - modular middleware to reuse across services and clients
122//! - full control from transport through TLS to HTTP and web protocols
123//!
124//! Learn more in the web servers chapter of the book:
125//! <https://ramaproxy.org/book/web_servers.html>.
126//!
127//! ### Datastar integration
128//!
129//! rama has built in support for [Datastar](https://data-star.dev) for reactive web
130//! applications using SSE. See the examples at
131//! <https://github.com/plabayo/rama/tree/main/examples> and the docs at:
132//!
133//! - <https://ramaproxy.org/docs/rama/http/sse/datastar/index.html>
134//! - <https://ramaproxy.org/docs/rama/http/service/web/extract/datastar/index.html>
135//! - <https://ramaproxy.org/docs/rama/http/service/web/response/struct.DatastarScript.html>
136//!
137//! ### Shuttle integration
138//!
139//! rama is supported by [Shuttle](https://www.shuttle.dev) via the `shuttle-rama` crate.
140//! You can deploy rama based services to Shuttle as described at
141//! <https://ramaproxy.org/book/deploy/shuttle.html>.
142//!
143//! ---
144//!
145//! ## Web clients
146//!
147//! A large part of rama is built on top of a service concept. A `Service` takes a `Request`
148//! and produces a `Response` or `Error`. Services can be leaf services or middlewares that
149//! wrap inner services.
150//!
151//! rama provides:
152//!
153//! - an `EasyHttpWebClient` for HTTP requests
154//! - many HTTP layers to tune timeouts, retries, telemetry and more
155//! - a high level `HttpClientExt` trait to build and send requests with a fluent API
156//!
157//! See the client example at
158//! <https://github.com/plabayo/rama/tree/main/examples/http_high_level_client.rs> and the
159//! docs at:
160//!
161//! - <https://ramaproxy.org/docs/rama/http/client/struct.EasyHttpWebClient.html>
162//! - <https://ramaproxy.org/docs/rama/http/service/client/trait.HttpClientExt.html>
163//!
164//! ---
165//!
166//! ## Ecosystem
167//!
168//! The `rama` crate can be used as the one and only dependency.
169//! However, as you can also read in the "DIY" chapter of the book
170//! at <https://ramaproxy.org/book/diy.html#empowering>, you are able
171//! to pick and choose not only what specific parts of `rama` you wish to use,
172//! but also in fact what specific (sub) crates.
173//!
174//! Here is a list of all `rama` crates:
175//!
176//! - [`rama`](https://crates.io/crates/rama): one crate to rule them all
177//! - [`rama-error`](https://crates.io/crates/rama-error): error utilities for rama and its users
178//! - [`rama-macros`](https://crates.io/crates/rama-macros): contains the procedural macros used by `rama`
179//! - [`rama-utils`](https://crates.io/crates/rama-utils): utilities crate for rama
180//! - [`rama-ws`](https://crates.io/crates/rama-ws): WebSocket (WS) support for rama
181//! - [`rama-core`](https://crates.io/crates/rama-core): core crate containing the service and layer traits
182//!   used by all other `rama` code, as well as some other _core_ utilities
183//! - [`rama-crypto`](https://crates.io/crates/rama-crypto): rama crypto primitives and dependencies
184//! - [`rama-net`](https://crates.io/crates/rama-net): rama network types and utilities
185//! - [`rama-dns`](https://crates.io/crates/rama-dns): DNS support for rama
186//! - [`rama-unix`](https://crates.io/crates/rama-unix): Unix (domain) socket support for rama
187//! - [`rama-tcp`](https://crates.io/crates/rama-tcp): TCP support for rama
188//! - [`rama-udp`](https://crates.io/crates/rama-udp): UDP support for rama
189//! - [`rama-tls-acme`](https://crates.io/crates/rama-tls-acme): ACME support for rama
190//! - [`rama-tls-boring`](https://crates.io/crates/rama-tls-boring): [Boring](https://github.com/plabayo/rama-boring) tls support for rama
191//! - [`rama-tls-rustls`](https://crates.io/crates/rama-tls-rustls): [Rustls](https://github.com/rustls/rustls) support for rama
192//! - [`rama-proxy`](https://crates.io/crates/rama-proxy): proxy types and utilities for rama
193//! - [`rama-socks5`](https://crates.io/crates/rama-socks5): SOCKS5 support for rama
194//! - [`rama-haproxy`](https://crates.io/crates/rama-haproxy): rama HAProxy support
195//! - [`rama-ua`](https://crates.io/crates/rama-ua): User-Agent (UA) support for `rama`
196//! - [`rama-http-types`](https://crates.io/crates/rama-http-types): http types and utilities
197//! - [`rama-http-headers`](https://crates.io/crates/rama-http-headers): typed http headers
198//! - [`rama-http`](https://crates.io/crates/rama-http): rama http services, layers and utilities
199//! - [`rama-http-backend`](https://crates.io/crates/rama-http-backend): default http backend for `rama`
200//! - [`rama-http-core`](https://crates.io/crates/rama-http-core): http protocol implementation driving `rama-http-backend`
201//! - [`rama-tower`](https://crates.io/crates/rama-tower): provide [tower](https://github.com/tower-rs/tower) compatibility for `rama`
202//!
203//! `rama` crates that live in <https://github.com/plabayo/rama-boring> (forks of `cloudflare/boring`):
204//!
205//! - [`rama-boring`](https://crates.io/crates/rama-boring): BoringSSL bindings for rama
206//! - [`rama-boring-sys`](https://crates.io/crates/rama-boring-sys): FFI bindings to BoringSSL for rama
207//! - [`rama-boring-tokio`](https://crates.io/crates/rama-boring-tokio): an implementation of SSL streams for Tokio backed by BoringSSL in function of rama
208//!
209//! repositories in function of rama that aren't crates:
210//!
211//! - <https://github.com/plabayo/rama-boringssl>:
212//!   Fork of [mirror of BoringSSL](https://github.com/plabayo/rama-boringssl)
213//!   in function of [rama-boring](https://github.com/plabayo/rama-boring)
214//! - <https://github.com/plabayo/homebrew-rama>: Homebrew formula for the rama Cli tool
215//!
216//! Repositories that we maintain and are re exported by the root `rama` crate:
217//!
218//! - <https://github.com/plabayo/tokio-graceful>: Graceful shutdown util for Rust projects using the Tokio Async runtime.
219//!
220//! Community crates that extend the ecosystem are encouraged. If you publish a community
221//! crate, please prefix it with `rama-x` so it is easy to discover and clearly distinct
222//! from the official crates in this repository.
223//!
224//! ---
225//!
226//! ## Safety and compatibility
227//!
228//! - rama crates avoid `unsafe` Rust as much as possible and use it only where necessary.
229//! - Supply chain auditing is done with [`cargo vet`](https://github.com/mozilla/cargo-vet).
230//! - Tier 1 platforms include macOS, Linux and Windows on modern architectures.
231//! - The minimum supported Rust version (MSRV) is `1.91`.
232//!
233//! For details see the compatibility section in the README and the CI configuration in
234//! the repository.
235//!
236//! ---
237//!
238//! ## License
239//!
240//! rama is free and open source software, dual licensed under MIT and Apache 2.0.
241//!
242//! You can use rama for commercial and non commercial purposes. If rama becomes an
243//! important part of your stack, please consider supporting the project as a sponsor
244//! or partner.
245//!
246//! ---
247//!
248//! ## Community and links
249//!
250//! - Official website: <https://ramaproxy.org>
251//! - Rama Book index: <https://ramaproxy.org/book>
252//! - Rust docs: <https://docs.rs/rama> (latest release) and <https://ramaproxy.org/docs/rama> (edge)
253//! - Repository and issues: <https://github.com/plabayo/rama>
254//! - Discord: <https://discord.gg/29EetaSYCD>
255//! - FAQ: <https://ramaproxy.org/book/faq.html>
256//! - Netstack FM podcast: <https://netstack.fm> (podcast about networking and Rust)
257//!
258//! If you are not sure where to start, read "Why rama" in the book, run a proxy example and then
259//! iterate from there with the book and docs at hand.
260
261#![doc(
262    html_favicon_url = "https://raw.githubusercontent.com/plabayo/rama/main/docs/img/old_logo.png"
263)]
264#![doc(html_logo_url = "https://raw.githubusercontent.com/plabayo/rama/main/docs/img/old_logo.png")]
265#![cfg_attr(docsrs, feature(doc_cfg))]
266#![cfg_attr(test, allow(clippy::float_cmp))]
267#![cfg_attr(
268    not(test),
269    warn(clippy::print_stdout, clippy::dbg_macro),
270    deny(clippy::unwrap_used, clippy::expect_used)
271)]
272
273#[doc(inline)]
274pub use ::rama_core::{
275    Layer, Service, ServiceInput, bytes, combinators, conversion, error, extensions, futures,
276    graceful, layer, matcher, rt, service, stream, username,
277};
278
279#[cfg(feature = "crypto")]
280#[cfg_attr(docsrs, doc(cfg(feature = "crypto")))]
281#[doc(inline)]
282pub use ::rama_crypto as crypto;
283
284#[cfg(all(target_family = "unix", feature = "net"))]
285#[cfg_attr(docsrs, doc(cfg(all(target_family = "unix", feature = "net"))))]
286#[doc(inline)]
287pub use ::rama_unix as unix;
288
289#[cfg(feature = "tcp")]
290#[cfg_attr(docsrs, doc(cfg(feature = "tcp")))]
291#[doc(inline)]
292pub use ::rama_tcp as tcp;
293
294#[cfg(feature = "udp")]
295#[cfg_attr(docsrs, doc(cfg(feature = "udp")))]
296#[doc(inline)]
297pub use ::rama_udp as udp;
298
299pub mod telemetry;
300
301#[cfg(any(feature = "rustls", feature = "boring", feature = "acme"))]
302#[cfg_attr(
303    docsrs,
304    doc(cfg(any(feature = "rustls", feature = "boring", feature = "acme")))
305)]
306pub mod tls;
307
308#[cfg(feature = "dns")]
309#[cfg_attr(docsrs, doc(cfg(feature = "dns")))]
310#[doc(inline)]
311pub use ::rama_dns as dns;
312
313#[cfg(feature = "net")]
314#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
315#[doc(inline)]
316pub use ::rama_net as net;
317
318#[cfg(feature = "http")]
319#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
320pub mod http;
321
322#[cfg(any(feature = "proxy", feature = "haproxy", feature = "socks5"))]
323#[cfg_attr(
324    docsrs,
325    doc(cfg(any(feature = "proxy", feature = "haproxy", feature = "socks5")))
326)]
327pub mod proxy {
328    //! rama proxy support
329
330    #[cfg(feature = "proxy")]
331    #[cfg_attr(docsrs, doc(cfg(feature = "proxy")))]
332    #[doc(inline)]
333    pub use ::rama_proxy::*;
334
335    #[cfg(feature = "haproxy")]
336    #[cfg_attr(docsrs, doc(cfg(feature = "haproxy")))]
337    #[doc(inline)]
338    pub use ::rama_haproxy as haproxy;
339
340    #[cfg(feature = "socks5")]
341    #[cfg_attr(docsrs, doc(cfg(feature = "socks5")))]
342    #[doc(inline)]
343    pub use ::rama_socks5 as socks5;
344}
345
346#[cfg(feature = "ua")]
347#[cfg_attr(docsrs, doc(cfg(feature = "ua")))]
348#[doc(inline)]
349pub use ::rama_ua as ua;
350
351#[cfg(feature = "cli")]
352#[cfg_attr(docsrs, doc(cfg(feature = "cli")))]
353pub mod cli;
354
355pub mod utils {
356    //! utilities for rama
357
358    #[doc(inline)]
359    pub use ::rama_utils::*;
360
361    #[cfg(feature = "tower")]
362    #[cfg_attr(docsrs, doc(cfg(feature = "tower")))]
363    #[doc(inline)]
364    pub use ::rama_tower as tower;
365}