sagebind / isahc

The practical HTTP client that is fun to use.

Home Page:https://docs.rs/isahc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug in auto_referer implementation

citreae535 opened this issue · comments

When isahc is asked to follow redirects with auto_referer enabled, it will add a Referer header to subsequent requests after being redirected. However, the current implementation does not remove previous Referer headers. Therefore, the final request will have multiple Referer headers if it is redirected more than once. This is different from curl --location --referer ";auto" which only retains the last Referer header. I think this is a bug and should be fixed.

isahc/src/redirect.rs

Lines 83 to 87 in 2a5c175

// Set referer header.
if auto_referer {
let referer = request_builder.uri_ref().unwrap().to_string();
request_builder = request_builder.header(http::header::REFERER, referer);
}

By the way, the current implementation also does not remove the fragment and userinfo components of the URI, a MUST NOT requirement in RFC 7231. curl conforms to the RFC, and it would be nice if isach does as well.

Good catch, thanks for letting me know about this! This is indeed the wrong behavior.