#header #axum #xrealip

headers-client-ip

A header for X-Real-IP compatible with headers crate

1 unstable release

0.1.0 Jun 27, 2022

#281 in #header

Download history 6/week @ 2024-12-08 1/week @ 2024-12-15 10/week @ 2025-02-02 65/week @ 2025-02-09 5/week @ 2025-02-16

80 downloads per month

Custom license

5KB
80 lines

headers-client-ip

Use with axum

let app = Router::new().route("/ws", get(ws_handler));

async fn ws_handler(
    ws: WebSocketUpgrade,
    ip: Option<TypedHeader<XRealIP>>,
) -> impl IntoResponse {
    if let Some(TypedHeader(user_ip)) = ip {
        println!("`{}` connected", user_ip);
    }

    ws.on_upgrade(handle_socket)
}

async fn handle_socket(mut socket: WebSocket) {
    //
}

Dependencies

~2MB
~38K SLoC