Function gotham::state::client_addr [] [src]

pub fn client_addr(state: &State) -> Option<SocketAddr>

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) {
    let addr = client_addr(&state).expect("no client address");

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

    (state, response)
}