http
http copied to clipboard
What is the recommended way of copying a `Request`?
Headers and body in particular.
Thanks.
My current "solution" for Uri rewriting:
fn req_sub_uri(req: Request<Body>, uri: Uri) -> Request<Body> {
let mut req = Request::builder()
.method(req.method())
.uri(uri)
.body(*req.body())
.unwrap();
let headers = req.headers_mut();
for (name, val) in req.headers() {
headers.insert(name, *val);
}
req
}
However, this doesn't look "Rusty".
fn req_sub_uri(mut req: Request<Body>, uri: Uri) -> Request<Body> {
*req.uri_mut() = uri;
req
}
@sfackler This is not good enough, unfortunately, for me, because Client#request
needs to move the request and I cannot reuse it.
@sfackler Thank you anyway, I ended up optimising the flow and using #uri_mut
.
Though my immediate problem is gone, this is not exactly a workaround, and I would really like this issue resolved.
Is there still no way to do this??
im trying to write some middleware to retry a failed request. This requires that you copy the request before calling it, but that doesnt seem to be possible with the current implementation. Am I correct? this is a very common usecase