extern crate ascii; extern crate base64; extern crate chunked_transfer; extern crate dns_lookup; extern crate encoding; #[macro_use] extern crate lazy_static; extern crate mime_guess; extern crate qstring; extern crate rustls; extern crate serde_json; extern crate url; extern crate webpki; extern crate webpki_roots; #[macro_use] mod agent; mod error; mod header; mod stream; mod util; #[cfg(test)] mod test; pub use agent::{Agent, Request, Response}; pub use header::Header; // re-export pub use serde_json::{to_value, Map, Value}; /// Agents keep state between requests. /// /// By default, no state, such as cookies, is kept between requests. /// But by creating an agent as entry point for the request, we /// can keep state. /// /// ``` /// let agent = ureq::agent(); /// /// let auth = agent /// .post("/login") /// .auth("martin", "rubbermashgum") /// .call(); // blocks. puts auth cookies in agent. /// /// if !auth.ok() { /// println!("Noes!"); /// } /// /// let secret = agent /// .get("/my-protected-page") /// .call(); // blocks and waits for request. /// /// if !secret.ok() { /// println!("Wot?!"); /// } /// /// println!("Secret is: {}", secret.into_string().unwrap()); /// ``` pub fn agent() -> Agent { Agent::new() } pub fn request(method: M, path: S) -> Request where M: Into, S: Into, { Agent::new().request(method, path) } pub fn get(path: S) -> Request where S: Into, { request("GET", path) } pub fn head(path: S) -> Request where S: Into, { request("HEAD", path) } pub fn post(path: S) -> Request where S: Into, { request("POST", path) } pub fn put(path: S) -> Request where S: Into, { request("PUT", path) } pub fn delete(path: S) -> Request where S: Into, { request("DELETE", path) } pub fn trace(path: S) -> Request where S: Into, { request("TRACE", path) } pub fn options(path: S) -> Request where S: Into, { request("OPTIONS", path) } pub fn connect(path: S) -> Request where S: Into, { request("CONNECT", path) } pub fn patch(path: S) -> Request where S: Into, { request("PATCH", path) } #[cfg(test)] mod tests { use super::*; #[test] fn connect_http_google() { let resp = get("http://www.google.com/").call(); println!("{:?}", resp); assert_eq!("text/html; charset=ISO-8859-1", resp.header("content-type").unwrap()); assert_eq!("text/html", resp.content_type()); } #[test] fn connect_https_google() { let resp = get("https://www.google.com/").call(); println!("{:?}", resp); assert_eq!("text/html; charset=ISO-8859-1", resp.header("content-type").unwrap()); assert_eq!("text/html", resp.content_type()); } }