Closed sdeleuze closed 2 years ago
This might be the easiest way for you:
for header in req.headers {
request = request.header(header.name, header.value);
}
I think the error you're seeing is nothing to do with headers_mut
being less safe (it's all safe), but rather that HeaderMap::insert
requires the name to be either a HeaderName
or a &'static str
, and I'm guessing header.name
is neither, but a &str
.
I see, thanks a lot for your feedback, much appreciated.
Hi,
Related to #191, I try to upgrade my
mini-http
fork tohttp
crate version0.2
(see related commit) but the new by-value request builder combined to the fact that I need to iterate to create various headers makes the migration non trivial, at least for a Rust newcomer like me.When I update:
to
I get the following error and I am not sure how to solve it:
I am still growing my Rust skills so I may have missed something obvious, but I have the feeling that
request.headers_mut()
is considered as less safe thanrequest.header()
by the Rust compiler but the by-value request builder does not allow me to userequest.header()
in a for loop. I have already tried to clone the data inserted the the headers map, still the same issue, so I am kind of stuck.Could you please share some guidance on how to upgrade for this use case and use that opportunity that the new API is designed for this kind of use case?
To reproduce the error: