ureq
ureq copied to clipboard
Getting the list of all the headers and their content
Hello,
I'm working on an API code generator. I want all the generated functions to return an access to all the headers and the parsed body.
To return all the headers I currently loop over response.headers_names() and then read the response.header(&name) :
pub(crate) fn get_header_map(response: &ureq::Response) -> HashMap<String, String> {
let mut headers = HashMap::new();
let names = response.headers_names();
for name in names {
if let Some(value) = response.header(&name) {
headers.insert(name, value.to_string());
}
}
headers
}
I find it very inefficient, the most efficient way from my point of view would be to add an access to the headers in the Response struct.
Do you think this would cause problems ? I can try to open a PR adding this function.
Edit: I found the "http-interop" feature, this could give me the access I want but I don't like the fact that unwrap() is called on into_string().
I got same problem.
But I prefer get_headers() -> &[Header], this is how it was stored in response after all. Then we can do other things on &[Header]
Closing since we're moving to ureq 3.x. This is solved in ureq 3.x