Using `http::header::HeaderMap` to create a request
- Dominant language
- Rust
- Stars
- 1.5k
- Forks
- 128
- PR merge metrics
- No merged PRs in 30d
Description
I currently have an `http::header::HeaderMap` that I want to use with my surf request, but I'm having a lot of trouble getting this to work. I tried a few approaches, but for one reason or another they just aren't feasible
1. Accessing the internal `http::Request` type doesn't work because `surf::Request::request()` returns a non-mutable reference. It doesn't seem possible to do what surf does internally (calling `self.req.as_mut().unwrap().headers_mut().insert(key, value)`)
1. Iterating over the `HeaderMap` doesn't seem to work because `surf::Request::set_header()` expects a `&'static str` for the key, but my `HeaderMap` has a non-static lifetime
Are there any suggestions on how this could be addressed? I could use a different type in place of `HeaderMap`, but I want to avoid this because surf will panic if the header value does not parse cleanly
It seems like surf deliberately lacks this API because it's more complicated than the current `set_header` API (I totally agree), but would it be possible to maybe add a `surf::Request::request_mut()` or `surf::Request::set_headers_from_map()`?
Contributor guide
Assessment
This issue has not been assessed yet.