1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! IP 工具: 客户端真实 IP 提取、可信代理校验、IP 格式与网段判断。
//!
//! [`client_ip`] 按以下优先级取客户端 IP:
//!
//! 1. `CF-Connecting-IP` (Cloudflare)
//! 2. `EO-Client-IP` (腾讯云 EdgeOne)
//! 3. `Ali-CDN-Real-IP` (阿里云 CDN)
//! 4. `X-HW-Real-IP` (华为云 CDN)
//! 5. `Baidu-Real-IP` (百度云 CDN)
//! 6. `X-Qiniu-CDN-Real-IP` (七牛云 CDN)
//! 7. `Cdn-Real-Ip` (网宿 CDN)
//! 8. `Fastly-Client-IP` (Fastly)
//! 9. `CloudFront-Viewer-Address` (AWS CloudFront, 自动去端口)
//! 10. `X-Azure-ClientIP` (Azure Front Door)
//! 11. `X-Real-IP` (Nginx 等通用代理)
//! 12. `X-Forwarded-For` 最左侧条目
//! 13. 直连地址
//!
//! # 信任边界
//!
//! 以上请求头都可被直连客户端伪造。[`client_ip`] 的结果只用于日志、展示与地域识别;
//! 鉴权、限流、封禁等安全决策必须用 [`TrustedProxies::client_ip`], 它要求显式声明
//! 部署边缘会覆盖的头, 直连来源不在可信网段时忽略一切转发头。
//!
//! ```
//! use std::net::IpAddr;
//! use http::HeaderMap;
//! use rust_web_utils::iputil::{self, TrustedProxies};
//!
//! let mut headers = HeaderMap::new();
//! headers.insert("cf-connecting-ip", "203.0.113.7".parse().unwrap());
//! let remote: IpAddr = "173.245.48.1".parse().unwrap();
//!
//! // 日志 / 展示
//! assert_eq!(iputil::client_ip(&headers, Some(remote)), "203.0.113.7");
//!
//! // 安全决策: 启动时构建一次
//! let tp = TrustedProxies::new("CF-Connecting-IP", ["173.245.48.0/20"]).unwrap();
//! assert_eq!(tp.client_ip(&headers, remote).to_string(), "203.0.113.7");
//! ```
//!
//! 完整文档: <https://rust-web-utils.czl.net/docs/iputil>
pub use ;
pub use ;
pub use ;