Skip to content

Commit

Permalink
referer updates
Browse files Browse the repository at this point in the history
- Don't set Referer if going from https to http
- Explicitly remove username, password, and fragment from Referer
  • Loading branch information
seanmonstar committed May 18, 2017
1 parent e00a64a commit d869604
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ impl RequestBuilder {
url = match loc {
Ok(loc) => {
if client.auto_referer.load(Ordering::Relaxed) {
headers.set(Referer(url.to_string()));
if let Some(referer) = make_referer(&loc, &url) {
headers.set(referer);
}
}
urls.push(url);
let action = check_redirect(&client.redirect_policy.lock().unwrap(), &loc, &urls);
Expand Down Expand Up @@ -383,6 +385,18 @@ impl fmt::Debug for RequestBuilder {
}
}

fn make_referer(next: &Url, previous: &Url) -> Option<Referer> {
if next.scheme() == "http" && previous.scheme() == "https" {
return None;
}

let mut referer = previous.clone();
let _ = referer.set_username("");
let _ = referer.set_password(None);
referer.set_fragment(None);
Some(Referer(referer.into_string()))
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit d869604

Please sign in to comment.