#ip-address #client-ip #remote #extractor #tiny #real #header

actix-remote-ip

Tiny extractor to get real client IP address, parsing X-Forwarded-For header

2 releases

0.1.0 Apr 29, 2023

#10 in #client-ip

Download history 206/week @ 2024-07-19 197/week @ 2024-07-26 43/week @ 2024-08-02 36/week @ 2024-08-09 40/week @ 2024-08-16 138/week @ 2024-08-23 80/week @ 2024-08-30 115/week @ 2024-09-06 162/week @ 2024-09-13 121/week @ 2024-09-20 133/week @ 2024-09-27 78/week @ 2024-10-04 100/week @ 2024-10-11 178/week @ 2024-10-18 83/week @ 2024-10-25 122/week @ 2024-11-01

498 downloads per month

GPL-2.0-or-later

10KB
187 lines

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

Dependencies

~15–26MB
~435K SLoC