feat(client): add a new Client struct with super powers

- Includes ergonomic traits like IntoUrl and IntoBody, allowing easy
usage.
- Client can have a RedirectPolicy.
- Client can have a SslVerifier.

Updated benchmarks for client. (Disabled rust-http client bench since it
hangs.)
This commit is contained in:
Sean McArthur
2014-10-17 14:59:01 -07:00
parent 9e99c57fa8
commit 8c83a3358e
13 changed files with 505 additions and 89 deletions

View File

@@ -138,6 +138,7 @@ extern crate mucell;
pub use std::io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr, Port};
pub use mimewrapper::mime;
pub use url::Url;
pub use client::Client;
pub use method::Method::{Get, Head, Post, Delete};
pub use status::StatusCode::{Ok, BadRequest, NotFound};
pub use server::Server;
@@ -181,6 +182,10 @@ macro_rules! inspect(
})
)
#[cfg(test)]
#[macro_escape]
mod mock;
pub mod client;
pub mod method;
pub mod header;
@@ -191,7 +196,6 @@ pub mod status;
pub mod uri;
pub mod version;
#[cfg(test)] mod mock;
mod mimewrapper {
/// Re-exporting the mime crate, for convenience.
@@ -208,7 +212,7 @@ pub enum HttpError {
/// An invalid `Method`, such as `GE,T`.
HttpMethodError,
/// An invalid `RequestUri`, such as `exam ple.domain`.
HttpUriError,
HttpUriError(url::ParseError),
/// An invalid `HttpVersion`, such as `HTP/1.1`
HttpVersionError,
/// An invalid `Header`.
@@ -223,7 +227,7 @@ impl Error for HttpError {
fn description(&self) -> &str {
match *self {
HttpMethodError => "Invalid Method specified",
HttpUriError => "Invalid Request URI specified",
HttpUriError(_) => "Invalid Request URI specified",
HttpVersionError => "Invalid HTTP version specified",
HttpHeaderError => "Invalid Header provided",
HttpStatusError => "Invalid Status provided",
@@ -234,6 +238,7 @@ impl Error for HttpError {
fn cause(&self) -> Option<&Error> {
match *self {
HttpIoError(ref error) => Some(error as &Error),
HttpUriError(ref error) => Some(error as &Error),
_ => None,
}
}
@@ -245,6 +250,12 @@ impl FromError<IoError> for HttpError {
}
}
impl FromError<url::ParseError> for HttpError {
fn from_error(err: url::ParseError) -> HttpError {
HttpUriError(err)
}
}
//FIXME: when Opt-in Built-in Types becomes a thing, we can force these structs
//to be Send. For now, this has the compiler do a static check.
fn _assert_send<T: Send>() {