extern crate ascii;
extern crate base64;
extern crate chunked_transfer;
extern crate cookie;
#[macro_use]
extern crate lazy_static;
extern crate qstring;
extern crate url;
#[cfg(feature = "charset")]
extern crate encoding;
#[cfg(feature = "tls")]
extern crate native_tls;
#[cfg(feature = "json")]
extern crate serde_json;
mod agent;
mod body;
mod error;
mod header;
mod macros;
mod pool;
mod response;
mod stream;
#[cfg(feature = "json")]
mod serde_macros;
#[cfg(test)]
mod test;
pub use agent::{Agent, Request};
pub use error::Error;
pub use header::Header;
pub use response::Response;
pub use cookie::Cookie;
#[cfg(feature = "json")]
pub use serde_json::{to_value as serde_to_value, Map as SerdeMap, Value as SerdeValue};
pub fn agent() -> Agent {
Agent::new().build()
}
pub fn request<M, S>(method: M, path: S) -> Request
where
M: Into<String>,
S: Into<String>,
{
Agent::new().request(method, path)
}
pub fn get<S>(path: S) -> Request
where
S: Into<String>,
{
request("GET", path)
}
pub fn head<S>(path: S) -> Request
where
S: Into<String>,
{
request("HEAD", path)
}
pub fn post<S>(path: S) -> Request
where
S: Into<String>,
{
request("POST", path)
}
pub fn put<S>(path: S) -> Request
where
S: Into<String>,
{
request("PUT", path)
}
pub fn delete<S>(path: S) -> Request
where
S: Into<String>,
{
request("DELETE", path)
}
pub fn trace<S>(path: S) -> Request
where
S: Into<String>,
{
request("TRACE", path)
}
pub fn options<S>(path: S) -> Request
where
S: Into<String>,
{
request("OPTIONS", path)
}
pub fn connect<S>(path: S) -> Request
where
S: Into<String>,
{
request("CONNECT", path)
}
pub fn patch<S>(path: S) -> Request
where
S: Into<String>,
{
request("PATCH", path)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn connect_http_google() {
let resp = get("http://www.google.com/").call();
assert_eq!(
"text/html; charset=ISO-8859-1",
resp.header("content-type").unwrap()
);
assert_eq!("text/html", resp.content_type());
}
#[test]
#[cfg(feature = "tls")]
fn connect_https_google() {
let resp = get("https://www.google.com/").call();
assert_eq!(
"text/html; charset=ISO-8859-1",
resp.header("content-type").unwrap()
);
assert_eq!("text/html", resp.content_type());
}
}