QUPSHDL6MQBVCRQPZ3O7MMG27FJYCASSOWN6LI6X5K3VOL7TCAVAC
let make_svc = make_service_fn(|_conn| async {
Ok::<_, Infallible>(service_fn(handle_reqs))
});
let make_svc = make_service_fn(move |conn: &AddrStream| {
let ip = conn.remote_addr().to_string();
async move {
Ok::<_, Infallible>(service_fn(move |req| handle_req(FullRequest{ req, ip: ip.clone() })))
}
}
);
use hyper::{
Body,
Request,
Response
};
use std::convert::Infallible;
/// All the info we need to produce a Zhur invocation from an HTTP request.
pub struct FullRequest {
/// The request itself.
pub req: Request<Body>,
/// The IP address the request is coming from, represented as a string.
pub ip: String,
}
/// Transforms an HTTP request into an HTTP response.
pub async fn handle_req(req: FullRequest) -> Result<Response<Body>, Infallible> {
let text = format!("Hi there, {}!", req.ip);
Ok(Response::new(text.into()))
}