Tiny crate to determine real client IP address on Actix
Go to file
Pierre HUBERT d1c957cc5a
All checks were successful
continuous-integration/drone/push Build is passing
Merge pull request 'Update Rust crate actix-web to v4.6.0' (#9) from renovate/actix-web-4.x-lockfile into master
Reviewed-on: #9
2024-05-24 13:12:51 +00:00
src Add base code (#1) 2023-04-29 09:00:57 +00:00
.drone.yml Add base code (#1) 2023-04-29 09:00:57 +00:00
.gitignore Initial commit 2023-04-29 10:06:53 +02:00
Cargo.lock Update Rust crate actix-web to v4.6.0 2024-05-24 00:23:46 +00:00
Cargo.toml Update Rust crate actix-web to 4.5.1 2024-04-26 00:15:00 +00:00
README.md Add base code (#1) 2023-04-29 09:00:57 +00:00
renovate.json Configure Renovate (#2) 2023-05-01 11:41:13 +00:00

Actix Remote IP extractor

Build Status Crate

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;
    // ...
}