Tiny crate to determine real client IP address on Actix
Pierre Hubert
2bbe8726f8
All checks were successful
continuous-integration/drone/push Build is passing
Welcome to [Renovate](https://github.com/renovatebot/renovate)! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin. 🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged. --- ### Detected Package Files * `Cargo.toml` (cargo) * `.drone.yml` (droneci) ### What to Expect It looks like your repository dependencies are already up-to-date and no Pull Requests will be necessary right away. --- ❓ Got questions? Check out Renovate's [Docs](https://docs.renovatebot.com/), particularly the Getting Started section. If you need any further assistance then you can also [request help here](https://github.com/renovatebot/renovate/discussions). --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Reviewed-on: #2 |
||
---|---|---|
src | ||
.drone.yml | ||
.gitignore | ||
Cargo.lock | ||
Cargo.toml | ||
README.md | ||
renovate.json |
Actix Remote IP extractor
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
Configuration
Configure it when you configure your Actix server:
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(RemoteIPConfig {
proxy: Some("IP".to_string())
}))
// ...
})
Usage
In your route, add a RemoteIP
parameter:
#[get("/")]
async fn home(remote_ip: RemoteIP) -> HttpResponse {
let ip: IpAddr = remote_ip.0;
// ...
}