Skip to content

Connection info

ConnectionInfo groups together information about the HTTP connection used to transmit the request you're currently processing.

ConnectionInfo gives you access to the peer address of the client that sent the request, via the ConnectionInfo::peer_addr method.
Many applications include the peer address in their request logs, for example.

Security implications

The peer address should not be treated as the clients IP address. Check out "The perils of the 'real' client IP" by Adam Pritchard to learn more about the issues you might run into.

Injection

Inject ConnectionInfo to access the peer address via its peer_addr method:

src/connection/peer.rs
use pavex::connection::ConnectionInfo;
use pavex::response::Response;

pub fn handler(conn: ConnectionInfo) -> Response {
    let addr = conn.peer_addr();
    Response::ok().set_typed_body(format!("Your address is {addr}"))
}