auth headers

This commit is contained in:
Martin Algesten
2018-06-11 22:44:32 +02:00
parent ea6c4b1f3b
commit 9852960bd7
4 changed files with 35 additions and 19 deletions

View File

@@ -16,7 +16,6 @@ pub struct Request {
// from request itself
headers: Vec<Header>,
auth: Option<(String, String)>,
query: QString,
timeout: u32,
timeout_read: u32,
@@ -62,7 +61,6 @@ impl Request {
method,
path,
headers: agent.headers.clone(),
auth: agent.auth.clone(),
redirects: 5,
..Default::default()
}
@@ -454,7 +452,9 @@ impl Request {
S: Into<String>,
T: Into<String>,
{
self.auth = Some((kind.into(), pass.into()));
let s = format!("Authorization: {} {}", kind.into(), pass.into());
let header = s.parse::<Header>().expect("Failed to parse header");
add_header(header, &mut self.headers);
self
}
@@ -505,9 +505,3 @@ impl Request {
.map_err(|e| Error::BadUrl(format!("{}", e)))
}
}
fn add_request_header(request: &mut Request, k: String, v: String) {
if let Ok(h) = Header::from_str(&format!("{}: {}", k, v)) {
request.headers.push(h)
}
}