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//! ---
138//!
139//! ## Web clients
140//!
141//! A large part of rama is built on top of a service concept. A `Service` takes a `Request`
142//! and produces a `Response` or `Error`. Services can be leaf services or middlewares that
143//! wrap inner services.
144//!
145//! rama provides:
146//!
147//! - an `EasyHttpWebClient` for HTTP requests
148//! - many HTTP layers to tune timeouts, retries, telemetry and more
149//! - a high level `HttpClientExt` trait to build and send requests with a fluent API
150//!
151//! See the client example at
152//! <https://github.com/plabayo/rama/tree/main/examples/http_high_level_client.rs> and the
153//! docs at:
154//!
155//! - <https://ramaproxy.org/docs/rama/http/client/struct.EasyHttpWebClient.html>
156//! - <https://ramaproxy.org/docs/rama/http/service/client/trait.HttpClientExt.html>
157//!
158//! ---
159//!
160//! ## Ecosystem
161//!
162//! The `rama` crate can be used as the one and only dependency.
163//! However, as you can also read in the "DIY" chapter of the book
164//! at <https://ramaproxy.org/book/diy.html#empowering>, you are able
165//! to pick and choose not only what specific parts of `rama` you wish to use,
166//! but also in fact what specific (sub) crates.
167//!
168//! Here is a list of all `rama` crates:
169//!
170//! - [`rama`](https://crates.io/crates/rama): one crate to rule them all
171//! - [`rama-error`](https://crates.io/crates/rama-error): error utilities for rama and its users
172//! - [`rama-macros`](https://crates.io/crates/rama-macros): contains the procedural macros used by `rama`
173//! - [`rama-utils`](https://crates.io/crates/rama-utils): utilities crate for rama
174//! - [`rama-ws`](https://crates.io/crates/rama-ws): WebSocket (WS) support for rama
175//! - [`rama-core`](https://crates.io/crates/rama-core): core crate containing the service and layer traits
176//! used by all other `rama` code, as well as some other _core_ utilities
177//! - [`rama-crypto`](https://crates.io/crates/rama-crypto): rama crypto primitives and dependencies
178//! - [`rama-net`](https://crates.io/crates/rama-net): rama network types and utilities
179//! - [`rama-net-apple-networkextension`](https://crates.io/crates/rama-net-apple-networkextension): Apple Network Extension support for rama
180//! - [`rama-dns`](https://crates.io/crates/rama-dns): DNS support for rama
181//! - [`rama-unix`](https://crates.io/crates/rama-unix): Unix (domain) socket support for rama
182//! - [`rama-tcp`](https://crates.io/crates/rama-tcp): TCP support for rama
183//! - [`rama-udp`](https://crates.io/crates/rama-udp): UDP support for rama
184//! - [`rama-tls-acme`](https://crates.io/crates/rama-tls-acme): ACME support for rama
185//! - [`rama-tls-boring`](https://crates.io/crates/rama-tls-boring): [Boring](https://github.com/plabayo/rama-boring) tls support for rama
186//! - [`rama-tls-rustls`](https://crates.io/crates/rama-tls-rustls): [Rustls](https://github.com/rustls/rustls) support for rama
187//! - [`rama-proxy`](https://crates.io/crates/rama-proxy): proxy types and utilities for rama
188//! - [`rama-socks5`](https://crates.io/crates/rama-socks5): SOCKS5 support for rama
189//! - [`rama-haproxy`](https://crates.io/crates/rama-haproxy): rama HAProxy support
190//! - [`rama-ua`](https://crates.io/crates/rama-ua): User-Agent (UA) support for `rama`
191//! - [`rama-http-types`](https://crates.io/crates/rama-http-types): http types and utilities
192//! - [`rama-http-headers`](https://crates.io/crates/rama-http-headers): typed http headers
193//! - [`rama-grpc`](https://crates.io/crates/rama-grpc): Grpc support for rama
194//! - [`rama-grpc-codegen`](https://crates.io/crates/rama-grpc-codegen): Grpc codegen support for rama
195//! - [`rama-http`](https://crates.io/crates/rama-http): rama http services, layers and utilities
196//! - [`rama-http-backend`](https://crates.io/crates/rama-http-backend): default http backend for `rama`
197//! - [`rama-http-core`](https://crates.io/crates/rama-http-core): http protocol implementation driving `rama-http-backend`
198//! - [`rama-tower`](https://crates.io/crates/rama-tower): provide [tower](https://github.com/tower-rs/tower) compatibility for `rama`
199//!
200//! `rama` crates that live in <https://github.com/plabayo/rama-boring> (forks of `cloudflare/boring`):
201//!
202//! - [`rama-boring`](https://crates.io/crates/rama-boring): BoringSSL bindings for rama
203//! - [`rama-boring-sys`](https://crates.io/crates/rama-boring-sys): FFI bindings to BoringSSL for rama
204//! - [`rama-boring-tokio`](https://crates.io/crates/rama-boring-tokio): an implementation of SSL streams for Tokio backed by BoringSSL in function of rama
205//!
206//! repositories in function of rama that aren't crates:
207//!
208//! - <https://github.com/plabayo/rama-boringssl>:
209//! Fork of [mirror of BoringSSL](https://github.com/plabayo/rama-boringssl)
210//! in function of [rama-boring](https://github.com/plabayo/rama-boring)
211//! - <https://github.com/plabayo/homebrew-rama>: Homebrew formula for the rama Cli tool
212//!
213//! Repositories that we maintain and are re exported by the root `rama` crate:
214//!
215//! - <https://github.com/plabayo/tokio-graceful>: Graceful shutdown util for Rust projects using the Tokio Async runtime.
216//!
217//! Community crates that extend the ecosystem are encouraged. If you publish a community
218//! crate, please prefix it with `rama-x` so it is easy to discover and clearly distinct
219//! from the official crates in this repository.
220//!
221//! ---
222//!
223//! ## Safety and compatibility
224//!
225//! - rama crates avoid `unsafe` Rust as much as possible and use it only where necessary.
226//! - Supply chain auditing is done with [`cargo vet`](https://github.com/mozilla/cargo-vet).
227//! - Tier 1 platforms include macOS, Linux and Windows on modern architectures.
228//! - The minimum supported Rust version (MSRV) is `1.93`.
229//!
230//! For details see the compatibility section in the README and the CI configuration in
231//! the repository.
232//!
233//! ---
234//!
235//! ## License
236//!
237//! rama is free and open source software, dual licensed under MIT and Apache 2.0.
238//!
239//! You can use rama for commercial and non commercial purposes. If rama becomes an
240//! important part of your stack, please consider supporting the project as a sponsor
241//! or partner.
242//!
243//! ---
244//!
245//! ## Community and links
246//!
247//! - Official website: <https://ramaproxy.org>
248//! - Rama Book index: <https://ramaproxy.org/book>
249//! - Rust docs: <https://docs.rs/rama> (latest release) and <https://ramaproxy.org/docs/rama> (edge)
250//! - Repository and issues: <https://github.com/plabayo/rama>
251//! - Discord: <https://discord.gg/29EetaSYCD>
252//! - FAQ: <https://ramaproxy.org/book/faq.html>
253//! - Netstack FM podcast: <https://netstack.fm> (podcast about networking and Rust)
254//!
255//! If you are not sure where to start, read "Why rama" in the book, run a proxy example and then
256//! iterate from there with the book and docs at hand.
257
258#![doc(
259 html_favicon_url = "https://raw.githubusercontent.com/plabayo/rama/main/docs/img/old_logo.png"
260)]
261#![doc(html_logo_url = "https://raw.githubusercontent.com/plabayo/rama/main/docs/img/old_logo.png")]
262#![cfg_attr(docsrs, feature(doc_cfg))]
263#![cfg_attr(test, allow(clippy::float_cmp))]
264#![cfg_attr(
265 not(test),
266 warn(clippy::print_stdout, clippy::dbg_macro),
267 deny(clippy::unwrap_used, clippy::expect_used)
268)]
269
270#[doc(inline)]
271pub use ::rama_core::{
272 Layer, Service, ServiceInput, bytes, combinators, conversion, error, extensions, futures,
273 graceful, io, layer, matcher, rt, service, stream, username,
274};
275
276#[cfg(feature = "crypto")]
277#[cfg_attr(docsrs, doc(cfg(feature = "crypto")))]
278#[doc(inline)]
279pub use ::rama_crypto as crypto;
280
281#[cfg(all(target_family = "unix", feature = "net"))]
282#[cfg_attr(docsrs, doc(cfg(all(target_family = "unix", feature = "net"))))]
283#[doc(inline)]
284pub use ::rama_unix as unix;
285
286#[cfg(feature = "tcp")]
287#[cfg_attr(docsrs, doc(cfg(feature = "tcp")))]
288#[doc(inline)]
289pub use ::rama_tcp as tcp;
290
291#[cfg(feature = "udp")]
292#[cfg_attr(docsrs, doc(cfg(feature = "udp")))]
293#[doc(inline)]
294pub use ::rama_udp as udp;
295
296pub mod telemetry;
297
298#[cfg(any(feature = "rustls", feature = "boring", feature = "acme"))]
299#[cfg_attr(
300 docsrs,
301 doc(cfg(any(feature = "rustls", feature = "boring", feature = "acme")))
302)]
303pub mod tls;
304
305#[cfg(feature = "dns")]
306#[cfg_attr(docsrs, doc(cfg(feature = "dns")))]
307#[doc(inline)]
308pub use ::rama_dns as dns;
309
310#[cfg(feature = "net")]
311pub mod net {
312 #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
313 #[doc(inline)]
314 pub use ::rama_net::*;
315
316 #[cfg(all(target_vendor = "apple", feature = "net-apple-networkextension"))]
317 #[cfg_attr(
318 docsrs,
319 doc(cfg(all(target_vendor = "apple", feature = "net-apple-networkextension")))
320 )]
321 pub mod apple {
322 //! Apple (vendor) specific network modules
323 #[doc(inline)]
324 pub use ::rama_net_apple_networkextension as networkextension;
325 }
326}
327
328#[cfg(all(target_vendor = "apple", feature = "net-apple-networkextension"))]
329#[cfg_attr(
330 docsrs,
331 doc(cfg(all(target_vendor = "apple", feature = "net-apple-networkextension")))
332)]
333#[doc(inline)]
334pub use ::rama_net_apple_networkextension::transparent_proxy_ffi;
335
336#[cfg(feature = "http")]
337#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
338pub mod http;
339
340#[cfg(any(feature = "proxy", feature = "haproxy", feature = "socks5"))]
341#[cfg_attr(
342 docsrs,
343 doc(cfg(any(feature = "proxy", feature = "haproxy", feature = "socks5")))
344)]
345pub mod proxy {
346 //! rama proxy support
347
348 #[cfg(feature = "proxy")]
349 #[cfg_attr(docsrs, doc(cfg(feature = "proxy")))]
350 #[doc(inline)]
351 pub use ::rama_proxy::*;
352
353 #[cfg(feature = "haproxy")]
354 #[cfg_attr(docsrs, doc(cfg(feature = "haproxy")))]
355 #[doc(inline)]
356 pub use ::rama_haproxy as haproxy;
357
358 #[cfg(feature = "socks5")]
359 #[cfg_attr(docsrs, doc(cfg(feature = "socks5")))]
360 #[doc(inline)]
361 pub use ::rama_socks5 as socks5;
362}
363
364#[cfg(feature = "ua")]
365#[cfg_attr(docsrs, doc(cfg(feature = "ua")))]
366#[doc(inline)]
367pub use ::rama_ua as ua;
368
369#[cfg(feature = "cli")]
370#[cfg_attr(docsrs, doc(cfg(feature = "cli")))]
371pub mod cli;
372
373pub mod utils {
374 //! utilities for rama
375
376 #[doc(inline)]
377 pub use ::rama_utils::*;
378
379 #[cfg(feature = "tower")]
380 #[cfg_attr(docsrs, doc(cfg(feature = "tower")))]
381 #[doc(inline)]
382 pub use ::rama_tower as tower;
383}