modo/ip/mod.rs
1//! # modo::ip
2//!
3//! Client IP extraction with trusted proxy support.
4//!
5//! Provides:
6//! - [`ClientIp`] — axum extractor wrapping `std::net::IpAddr`
7//! - [`ClientInfo`] — structured client metadata (IP, user-agent, etc.) inserted
8//! into request extensions by [`ClientIpLayer`]
9//! - [`ClientIpLayer`] — Tower layer that resolves the client IP and inserts
10//! [`ClientIp`] / [`ClientInfo`] into request extensions
11//! - [`extract_client_ip`] — low-level resolution function (headers + trusted
12//! proxies + fallback)
13//!
14//! ## Quick start
15//!
16//! ```rust,no_run
17//! use axum::{Router, routing::get};
18//! use modo::ip::{ClientIp, ClientIpLayer};
19//!
20//! let app: Router = Router::new()
21//! .route("/", get(handler))
22//! .layer(ClientIpLayer::new());
23//!
24//! async fn handler(ClientIp(ip): ClientIp) -> String {
25//! ip.to_string()
26//! }
27//! ```
28
29mod client_info;
30mod client_ip;
31mod extract;
32mod middleware;
33
34pub use client_info::ClientInfo;
35pub use client_ip::ClientIp;
36pub use extract::extract_client_ip;
37pub use middleware::ClientIpLayer;