cargo fmt
This commit is contained in:
@@ -324,7 +324,6 @@ impl Agent {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn basic_auth(user: &str, pass: &str) -> String {
|
||||
let safe = match user.find(":") {
|
||||
Some(idx) => &user[..idx],
|
||||
@@ -333,7 +332,6 @@ fn basic_auth(user: &str, pass: &str) -> String {
|
||||
::base64::encode(&format!("{}:{}", safe, pass))
|
||||
}
|
||||
|
||||
|
||||
fn mime_of<S: Into<String>>(s: S) -> String {
|
||||
let s = s.into();
|
||||
match &s[..] {
|
||||
@@ -346,7 +344,6 @@ fn mime_of<S: Into<String>>(s: S) -> String {
|
||||
}.to_string()
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::io::Error as IoError;
|
||||
use native_tls::Error as TlsError;
|
||||
use native_tls::HandshakeError;
|
||||
use std::io::Error as IoError;
|
||||
use std::net::TcpStream;
|
||||
|
||||
/// Errors that are translated to ["synthetic" responses](struct.Response.html#method.synthetic).
|
||||
@@ -29,7 +29,6 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl Error {
|
||||
|
||||
/// For synthetic responses, this is the error code.
|
||||
pub fn status(&self) -> u16 {
|
||||
match self {
|
||||
@@ -52,7 +51,7 @@ impl Error {
|
||||
Error::BadUrl(e) => {
|
||||
println!("{}", e);
|
||||
"Bad URL"
|
||||
},
|
||||
}
|
||||
Error::UnknownScheme(_) => "Unknown Scheme",
|
||||
Error::DnsFailed(_) => "Dns Failed",
|
||||
Error::ConnectionFailed(_) => "Connection Failed",
|
||||
|
||||
@@ -54,9 +54,9 @@ extern crate encoding;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate mime_guess;
|
||||
extern crate native_tls;
|
||||
extern crate qstring;
|
||||
extern crate serde_json;
|
||||
extern crate native_tls;
|
||||
extern crate url;
|
||||
|
||||
mod agent;
|
||||
@@ -69,12 +69,12 @@ mod serde_macros;
|
||||
mod test;
|
||||
|
||||
pub use agent::{Agent, Request, Response};
|
||||
pub use header::Header;
|
||||
pub use error::Error;
|
||||
pub use header::Header;
|
||||
|
||||
// re-export
|
||||
pub use serde_json::{to_value as serde_to_value, Map as SerdeMap, Value as SerdeValue};
|
||||
pub use cookie::Cookie;
|
||||
pub use serde_json::{to_value as serde_to_value, Map as SerdeMap, Value as SerdeValue};
|
||||
|
||||
/// Agents are used to keep state between requests.
|
||||
pub fn agent() -> Agent {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/// Create a `HashMap` from a shorthand notation.
|
||||
///
|
||||
/// ```
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
// this file is borrowed in its entirety until macro_reexport stabilizes.
|
||||
// https://github.com/rust-lang/rust/issues/29638
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@ use super::super::*;
|
||||
|
||||
#[test]
|
||||
fn agent_reuse_headers() {
|
||||
let agent = agent()
|
||||
.set("Authorization", "Foo 12345")
|
||||
.build();
|
||||
let agent = agent().set("Authorization", "Foo 12345").build();
|
||||
|
||||
test::set_handler("/agent_reuse_headers", |req, _url| {
|
||||
assert!(req.has("Authorization"));
|
||||
@@ -27,14 +25,17 @@ fn agent_reuse_headers() {
|
||||
assert_eq!(resp.header("X-Call").unwrap(), "2");
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn agent_cookies() {
|
||||
let agent = agent()
|
||||
.build();
|
||||
let agent = agent().build();
|
||||
|
||||
test::set_handler("/agent_cookies", |_req, _url| {
|
||||
test::make_response(200, "OK", vec!["Set-Cookie: foo=bar%20baz; Path=/; HttpOnly"], vec![])
|
||||
test::make_response(
|
||||
200,
|
||||
"OK",
|
||||
vec!["Set-Cookie: foo=bar%20baz; Path=/; HttpOnly"],
|
||||
vec![],
|
||||
)
|
||||
});
|
||||
|
||||
agent.get("test://host/agent_cookies").call();
|
||||
@@ -52,5 +53,4 @@ fn agent_cookies() {
|
||||
let s = String::from_utf8_lossy(&vec);
|
||||
|
||||
assert!(s.contains("Cookie: foo=bar%20baz\r\n"));
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ use super::super::*;
|
||||
#[test]
|
||||
fn basic_auth() {
|
||||
test::set_handler("/basic_auth", |req, _url| {
|
||||
assert_eq!(req.header("Authorization").unwrap(), "Basic bWFydGluOnJ1YmJlcm1hc2hndW0=");
|
||||
assert_eq!(
|
||||
req.header("Authorization").unwrap(),
|
||||
"Basic bWFydGluOnJ1YmJlcm1hc2hndW0="
|
||||
);
|
||||
test::make_response(200, "OK", vec![], vec![])
|
||||
});
|
||||
let resp = get("test://host/basic_auth")
|
||||
|
||||
@@ -42,14 +42,16 @@ fn content_length_limited() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
// content-length should be ignored when chunked
|
||||
fn ignore_content_length_when_chunked() {
|
||||
// content-length should be ignored when chunked
|
||||
fn ignore_content_length_when_chunked() {
|
||||
test::set_handler("/ignore_content_length_when_chunked", |_req, _url| {
|
||||
test::make_response(
|
||||
200,
|
||||
"OK",
|
||||
vec!["Content-Length: 4", "transfer-encoding: chunked"],
|
||||
"3\r\nhel\r\nb\r\nlo world!!!\r\n0\r\n\r\n".to_string().into_bytes(),
|
||||
"3\r\nhel\r\nb\r\nlo world!!!\r\n0\r\n\r\n"
|
||||
.to_string()
|
||||
.into_bytes(),
|
||||
)
|
||||
});
|
||||
let resp = get("test://host/ignore_content_length_when_chunked").call();
|
||||
@@ -57,4 +59,4 @@ fn content_length_limited() {
|
||||
let mut text = String::new();
|
||||
reader.read_to_string(&mut text).unwrap();
|
||||
assert_eq!(text, "hello world!!!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ fn content_length_on_str() {
|
||||
test::set_handler("/content_length_on_str", |_req, _url| {
|
||||
test::make_response(200, "OK", vec![], vec![])
|
||||
});
|
||||
let resp = get("test://host/content_length_on_str")
|
||||
.send_string("Hello World!!!");
|
||||
let resp = post("test://host/content_length_on_str").send_string("Hello World!!!");
|
||||
let vec = resp.to_write_vec();
|
||||
let s = String::from_utf8_lossy(&vec);
|
||||
assert!(s.contains("\r\nContent-Length: 14\r\n"));
|
||||
@@ -19,7 +18,7 @@ fn user_set_content_length_on_str() {
|
||||
test::set_handler("/user_set_content_length_on_str", |_req, _url| {
|
||||
test::make_response(200, "OK", vec![], vec![])
|
||||
});
|
||||
let resp = get("test://host/user_set_content_length_on_str")
|
||||
let resp = post("test://host/user_set_content_length_on_str")
|
||||
.set("Content-Length", "12345")
|
||||
.send_string("Hello World!!!");
|
||||
let vec = resp.to_write_vec();
|
||||
@@ -33,9 +32,11 @@ fn content_length_on_json() {
|
||||
test::make_response(200, "OK", vec![], vec![])
|
||||
});
|
||||
let mut json = SerdeMap::new();
|
||||
json.insert("Hello".to_string(), SerdeValue::String("World!!!".to_string()));
|
||||
let resp = get("test://host/content_length_on_json")
|
||||
.send_json(SerdeValue::Object(json));
|
||||
json.insert(
|
||||
"Hello".to_string(),
|
||||
SerdeValue::String("World!!!".to_string()),
|
||||
);
|
||||
let resp = post("test://host/content_length_on_json").send_json(SerdeValue::Object(json));
|
||||
let vec = resp.to_write_vec();
|
||||
let s = String::from_utf8_lossy(&vec);
|
||||
assert!(s.contains("\r\nContent-Length: 20\r\n"));
|
||||
@@ -53,4 +54,4 @@ fn content_length_and_chunked() {
|
||||
let s = String::from_utf8_lossy(&vec);
|
||||
assert!(s.contains("Transfer-Encoding: chunked\r\n"));
|
||||
assert!(!s.contains("\r\nContent-Length:\r\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ use agent::Stream;
|
||||
use error::Error;
|
||||
use header::Header;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Cursor;
|
||||
use std::io::Write;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use url::Url;
|
||||
use std::io::Cursor;
|
||||
|
||||
mod agent_test;
|
||||
mod auth;
|
||||
|
||||
@@ -7,8 +7,7 @@ fn no_query_string() {
|
||||
test::set_handler("/no_query_string", |_req, _url| {
|
||||
test::make_response(200, "OK", vec![], vec![])
|
||||
});
|
||||
let resp = get("test://host/no_query_string")
|
||||
.call();
|
||||
let resp = get("test://host/no_query_string").call();
|
||||
let vec = resp.to_write_vec();
|
||||
let s = String::from_utf8_lossy(&vec);
|
||||
assert!(s.contains("GET /no_query_string HTTP/1.1"))
|
||||
|
||||
@@ -35,10 +35,10 @@ fn repeat_x_header() {
|
||||
test::set_handler("/repeat_x_header", |req, _url| {
|
||||
assert!(req.has("X-Forwarded-For"));
|
||||
assert_eq!(req.header("X-Forwarded-For").unwrap(), "130.240.19.2");
|
||||
assert_eq!(req.all("X-Forwarded-For"), vec![
|
||||
"130.240.19.2",
|
||||
"130.240.19.3",
|
||||
]);
|
||||
assert_eq!(
|
||||
req.all("X-Forwarded-For"),
|
||||
vec!["130.240.19.2", "130.240.19.3"]
|
||||
);
|
||||
test::make_response(200, "OK", vec![], vec![])
|
||||
});
|
||||
let resp = get("test://host/repeat_x_header")
|
||||
|
||||
Reference in New Issue
Block a user