Skip to main content

netray_common/
lib.rs

1//! Shared utilities for the netray.info service ecosystem.
2//!
3//! This crate provides cross-cutting concerns used by multiple backend services:
4//!
5//! - [`ip_extract`] -- Extract real client IP from proxy headers with trusted-proxy CIDR matching.
6//! - [`error`] -- Structured JSON error responses via the [`error::ApiError`] trait.
7//! - [`rate_limit`] -- Keyed and global rate limiting wrappers around `governor`.
8//! - [`security_headers`] -- Axum middleware for CSP, HSTS, and other security headers.
9//!
10//! # Example
11//!
12//! ```rust
13//! use netray_common::ip_extract::IpExtractor;
14//!
15//! let extractor = IpExtractor::new(&["10.0.0.0/8".to_string()]);
16//! // extractor.extract(&headers, peer_addr) returns the real client IP
17//! ```
18
19#[cfg(feature = "cors")]
20pub mod cors;
21pub mod ecosystem;
22#[cfg(feature = "enrichment")]
23pub mod enrichment;
24pub mod error;
25pub mod ip_extract;
26pub mod ip_filter;
27pub mod metrics;
28#[cfg(feature = "middleware")]
29pub mod middleware;
30pub mod rate_limit;
31pub mod security_headers;
32#[cfg(feature = "server")]
33pub mod server;
34pub mod target_policy;
35#[cfg(feature = "telemetry")]
36pub mod telemetry;