Function gotham::state::client_addr

source ·
pub fn client_addr(state: &State) -> Option<SocketAddr>
Expand description

Returns the client SocketAddr as reported by hyper, if one was present. Certain connections do not report a client address, in which case this will return None.

Examples

fn my_handler(state: State) -> (State, Response<Body>) {
    let addr = client_addr(&state).expect("no client address");

    let body = format!("{}", addr);
    let response = create_response(
        &state,
        StatusCode::OK,
        mime::TEXT_PLAIN,
        body,
    );

    (state, response)
}