http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.45k stars 119 forks source link

Multiple headers of same type are not being properly saved in response #297

Closed jacobmischka closed 3 years ago

jacobmischka commented 3 years ago

Apologies in advance, this report is going to be pretty awful, because I'm encountering this issue when accessing a private URL and I don't have a good test bed set up at the moment.

I'm posting to a URL, that when accessed using cURL, python via requests, and a web browser responds correctly with two set-cookie headers. Surf is only returning the second of the two headers, despite the documentation claiming that it should contain all of them.

This only returns the second header:

        let response = surf::post(URL)
            .body(surf::Body::from_form(&form)?)
            .send()
            .await?;

        let headers = response
            .header(surf::http::headers::SET_COOKIE).unwrap();

        dbg!(headers.get(0)); // Some("cookie2")
        dbg!(headers.get(1)); // None

But when inspecting an identical request from cURL:

< HTTP/1.1 302 Found
< Cache-Control: no-store, no-cache, must-revalidate
< Pragma: no-cache
< Set-Cookie: cookie1
< Set-Cookie: cookie2
< Location: <redirect-url>
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8

Or when using requests in python it correctly returns both:

import requests

response = requests.post(
    URL,
    data=form,
    allow_redirects=False,
)

print(response.headers["set-cookie"]) # "cookie1, cookie2"

Apologies again for the lack of details, I'll try to put together/find some test endpoint that returns two set-cookie headers to provide as reproduction soon.

jacobmischka commented 3 years ago

Ah, this is actually a bug in http_client. I will be submitting a PR there shortly that fixes the issue.

Fishrock123 commented 3 years ago

Should be fixed in http-client 6.3.5 if you cargo update!

jacobmischka commented 3 years ago

Thanks for the quick response!