wip
This commit is contained in:
@@ -44,3 +44,6 @@ path = "examples/simple.rs"
|
|||||||
name = "async"
|
name = "async"
|
||||||
path = "examples/async.rs"
|
path = "examples/async.rs"
|
||||||
required-features = ["unstable"]
|
required-features = ["unstable"]
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
features = ["unstable"]
|
||||||
|
|||||||
@@ -23,6 +23,33 @@ static DEFAULT_USER_AGENT: &'static str =
|
|||||||
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
/// An asynchornous `Client` to make Requests with.
|
/// An asynchornous `Client` to make Requests with.
|
||||||
|
///
|
||||||
|
/// The Client has various configuration values to tweak, but the defaults
|
||||||
|
/// are set to what is usually the most commonly desired value.
|
||||||
|
///
|
||||||
|
/// The `Client` holds a connection pool internally, so it is advised that
|
||||||
|
/// you create one and **reuse** it.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # #[cfg(features = "unstable")]
|
||||||
|
/// # fn run() -> Result<(), Box<::std::error::Error>> {
|
||||||
|
/// # extern crate tokio_core;
|
||||||
|
/// # extern crate futures;
|
||||||
|
/// use futures::Future;
|
||||||
|
/// use tokio_core::reactor::Core;
|
||||||
|
/// use reqwest::unstable::async::Client;
|
||||||
|
///
|
||||||
|
/// let mut core = Core::new()?;
|
||||||
|
/// let client = Client::new(&core.handle());
|
||||||
|
/// let fut = client.get("http://httpbin.org/").send();
|
||||||
|
/// core.run(fut)?;
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// # fn main() {}
|
||||||
|
/// ```
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
inner: Arc<ClientRef>,
|
inner: Arc<ClientRef>,
|
||||||
|
|||||||
@@ -51,21 +51,21 @@ impl Response {
|
|||||||
&mut self.headers
|
&mut self.headers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a readable response body.
|
/// Get a reference to the response body.
|
||||||
|
#[inline]
|
||||||
|
pub fn body(&self) -> &Decoder {
|
||||||
|
&self.body
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a mutable reference to the response body.
|
||||||
///
|
///
|
||||||
/// The response will be decoded.
|
/// The chunks from the body may be decoded, depending on the `gzip`
|
||||||
|
/// option on the `ClientBuilder`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn body_mut(&mut self) -> &mut Decoder {
|
pub fn body_mut(&mut self) -> &mut Decoder {
|
||||||
&mut self.body
|
&mut self.body
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a readable response body.
|
|
||||||
///
|
|
||||||
/// This function will replace the body on the response with an empty one.
|
|
||||||
#[inline]
|
|
||||||
pub fn body(&self) -> &Decoder {
|
|
||||||
&self.body
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Try to deserialize the response body as JSON using `serde`.
|
/// Try to deserialize the response body as JSON using `serde`.
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -79,28 +79,28 @@ impl Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Turn a response into an error if the server returned an error.
|
/// Turn a response into an error if the server returned an error.
|
||||||
// XXX: example disabled since rustdoc still tries to run it
|
///
|
||||||
// when the 'unstable' feature isn't active, making the import
|
/// # Example
|
||||||
// fail.
|
///
|
||||||
//
|
/// ```
|
||||||
// # Example
|
/// # #[cfg(feature="unstable")]
|
||||||
//
|
/// # use reqwest::unstable::async::Response;
|
||||||
// ```
|
/// # #[cfg(feature="unstable")]
|
||||||
// # use reqwest::unstable::async::Response;
|
/// fn on_response(res: Response) {
|
||||||
// fn on_response(res: Response) {
|
/// match res.error_for_status() {
|
||||||
// match res.error_for_status() {
|
/// Ok(_res) => (),
|
||||||
// Ok(_res) => (),
|
/// Err(err) => {
|
||||||
// Err(err) => {
|
/// // asserting a 400 as an example
|
||||||
// // asserting a 400 as an example
|
/// // it could be any status between 400...599
|
||||||
// // it could be any status between 400...599
|
/// assert_eq!(
|
||||||
// assert_eq!(
|
/// err.status(),
|
||||||
// err.status(),
|
/// Some(reqwest::StatusCode::BadRequest)
|
||||||
// Some(reqwest::StatusCode::BadRequest)
|
/// );
|
||||||
// );
|
/// }
|
||||||
// }
|
/// }
|
||||||
// }
|
/// }
|
||||||
// }
|
/// # fn main() {}
|
||||||
// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn error_for_status(self) -> ::Result<Self> {
|
pub fn error_for_status(self) -> ::Result<Self> {
|
||||||
if self.status.is_client_error() {
|
if self.status.is_client_error() {
|
||||||
|
|||||||
@@ -177,14 +177,16 @@ pub mod multipart;
|
|||||||
|
|
||||||
/// A set of unstable functionality.
|
/// A set of unstable functionality.
|
||||||
///
|
///
|
||||||
/// This module is only available when the `unstable` feature is enabled.
|
/// This module is only available when the `unstable` [feature][] is enabled.
|
||||||
/// There is no backwards compatibility guarantee for any of the types within.
|
/// There is no backwards compatibility guarantee for any of the types within.
|
||||||
|
///
|
||||||
|
/// [feature]: http://doc.crates.io/specifying-dependencies.html#choosing-features
|
||||||
#[cfg(feature = "unstable")]
|
#[cfg(feature = "unstable")]
|
||||||
pub mod unstable {
|
pub mod unstable {
|
||||||
/// An 'async' implementation of the reqwest `Client`.
|
/// An 'async' implementation of the reqwest `Client`.
|
||||||
///
|
///
|
||||||
/// Relies on the `futures` crate, which is unstable, hence this module
|
/// Relies on the `futures` crate, which is unstable, hence this module
|
||||||
/// is unstable.
|
/// is **unstable**.
|
||||||
pub mod async {
|
pub mod async {
|
||||||
pub use ::async_impl::{
|
pub use ::async_impl::{
|
||||||
Body,
|
Body,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
extern crate tokio_core;
|
extern crate tokio_core;
|
||||||
extern crate tokio_io;
|
|
||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
extern crate libflate;
|
extern crate libflate;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user