Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the list of all the headers and their content #655

Closed
nponsard opened this issue Sep 6, 2023 · 2 comments
Closed

Getting the list of all the headers and their content #655

nponsard opened this issue Sep 6, 2023 · 2 comments

Comments

@nponsard
Copy link

nponsard commented Sep 6, 2023

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().

@nponsard nponsard changed the title Getting the list of all the headers and its content Getting the list of all the headers and their content Sep 6, 2023
@flaribbit
Copy link

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]

@algesten
Copy link
Owner

Closing since we're moving to ureq 3.x. This is solved in ureq 3.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants