let new_service = make_service_fn(move |conn: &AddrStream| {
let remote_addr = conn.remote_addr().ip();
async move {
Ok::<_, GenericError>(service_fn(move |req| {
let req_clone = req.clone();
let remote_addr_clone = remote_addr.clone();
handle(remote_addr, req);
doStuffWith(req_clone);
}))
}
});
But apparently, clone is not a part of the http:request:Request object. How do we get the a values-only copy of the Request object without making it into a JSON string and serializing and parsing it?
You can't clone a request because it might have a Body object, which makes the body available using a streaming technique, making it impossible to clone. If you just want the headers, you can use into_parts to obtain the Parts struct that contains e.g. the Uri and stuff. You can clone the first four fields of Parts, but Parts is not Clone as the extensions field can't be cloned either.
This is the message I get when I try to use try_clone there:
Request<Body>
no method named `try_clone` found for struct `http::request::Request<_>` in the current scope
method not found in `http::request::Request<_>`rustc(E0599)
It does not seem to have clone, try_clone, etc here...