Crates.io | actix-remote-ip |
lib.rs | actix-remote-ip |
version | 0.1.0 |
source | src |
created_at | 2023-04-29 08:34:15.465905 |
updated_at | 2023-04-29 09:02:05.938341 |
description | Tiny extractor to get real client IP address, parsing X-Forwarded-For header |
homepage | |
repository | https://gitea.communiquons.org/pierre/actix-remote-ip |
max_upload_size | |
id | 851927 |
size | 9,694 |
Tiny extractor of remote user IP address, that handles reverse proxy.
The X-Forwarded-For
header is automatically parsed when the request comes from a defined proxy, to determine the real remote client IP Address.
Note : regarding IPv6 addresses, the local part of the address is discarded. For example, the IPv6 client 2001:0db8:85a3:0000:0000:8a2e:0370:7334
will be returned as 2001:0db8:85a3:0000:0000:0000:0000:0000
Configure it when you configure your Actix server:
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(RemoteIPConfig {
proxy: Some("IP".to_string())
}))
// ...
})
In your route, add a RemoteIP
parameter:
#[get("/")]
async fn home(remote_ip: RemoteIP) -> HttpResponse {
let ip: IpAddr = remote_ip.0;
// ...
}