Make the blocking API an optional feature (default off)
This commit is contained in:
@@ -60,7 +60,7 @@ impl Decoder {
|
||||
/// An empty decoder.
|
||||
///
|
||||
/// This decoder will produce a single 0 byte chunk.
|
||||
#[inline]
|
||||
#[cfg(feature = "blocking")]
|
||||
pub(crate) fn empty() -> Decoder {
|
||||
Decoder {
|
||||
inner: Inner::PlainText(Body::empty().into_stream()),
|
||||
|
||||
@@ -346,6 +346,7 @@ impl Response {
|
||||
// on the `Response` itself.
|
||||
//
|
||||
// This method is just used by the blocking API.
|
||||
#[cfg(feature = "blocking")]
|
||||
pub(crate) fn body_mut(&mut self) -> &mut Decoder {
|
||||
&mut self.body
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
//! The blocking `Client` will block the current thread to execute, instead
|
||||
//! of returning futures that need to be executed on a runtime.
|
||||
//!
|
||||
//! ## Making a GET request
|
||||
//! # Optional
|
||||
//!
|
||||
//! This requires the optional `blocking` feature to be enabled.
|
||||
//!
|
||||
//! # Making a GET request
|
||||
//!
|
||||
//! For a single request, you can use the [`get`](get) shortcut method.
|
||||
//!
|
||||
@@ -28,7 +32,7 @@
|
||||
//! [`Client`](Client) and reuse it, taking advantage of keep-alive connection
|
||||
//! pooling.
|
||||
//!
|
||||
//! ## Making POST requests (or setting request bodies)
|
||||
//! # Making POST requests (or setting request bodies)
|
||||
//!
|
||||
//! There are several ways you can set the body of a request. The basic one is
|
||||
//! by using the `body()` method of a [`RequestBuilder`](RequestBuilder). This lets you set the
|
||||
|
||||
@@ -290,7 +290,7 @@ impl Response {
|
||||
where
|
||||
W: io::Write,
|
||||
{
|
||||
io::copy(self, w).map_err(crate::error::response)
|
||||
io::copy(self, w).map_err(crate::error::decode_io)
|
||||
}
|
||||
|
||||
/// Turn a response into an error if the server returned an error.
|
||||
@@ -365,8 +365,8 @@ impl Read for Response {
|
||||
|
||||
let timeout = self.timeout;
|
||||
wait::timeout(self.body_mut().read(buf), timeout).map_err(|e| match e {
|
||||
wait::Waited::TimedOut(e) => crate::error::response(e).into_io(),
|
||||
wait::Waited::Executor(e) => crate::error::response(e).into_io(),
|
||||
wait::Waited::TimedOut(e) => crate::error::decode(e).into_io(),
|
||||
wait::Waited::Executor(e) => crate::error::decode(e).into_io(),
|
||||
wait::Waited::Inner(e) => e,
|
||||
})
|
||||
}
|
||||
|
||||
11
src/error.rs
11
src/error.rs
@@ -138,7 +138,6 @@ impl fmt::Display for Error {
|
||||
match self.inner.kind {
|
||||
Kind::Builder => f.write_str("builder error")?,
|
||||
Kind::Request => f.write_str("error sending request")?,
|
||||
Kind::Response => f.write_str("error reading response")?,
|
||||
Kind::Body => f.write_str("request or response body error")?,
|
||||
Kind::Decode => f.write_str("error decoding response body")?,
|
||||
Kind::Redirect => f.write_str("error following redirect")?,
|
||||
@@ -173,7 +172,6 @@ impl StdError for Error {
|
||||
pub(crate) enum Kind {
|
||||
Builder,
|
||||
Request,
|
||||
Response,
|
||||
Redirect,
|
||||
Status(StatusCode),
|
||||
Body,
|
||||
@@ -198,10 +196,6 @@ pub(crate) fn request<E: Into<BoxError>>(e: E) -> Error {
|
||||
Error::new(Kind::Request, Some(e))
|
||||
}
|
||||
|
||||
pub(crate) fn response<E: Into<BoxError>>(e: E) -> Error {
|
||||
Error::new(Kind::Response, Some(e))
|
||||
}
|
||||
|
||||
pub(crate) fn loop_detected(url: Url) -> Error {
|
||||
Error::new(Kind::Redirect, Some("infinite redirect loop detected")).with_url(url)
|
||||
}
|
||||
@@ -220,6 +214,7 @@ pub(crate) fn url_bad_scheme(url: Url) -> Error {
|
||||
|
||||
// io::Error helpers
|
||||
|
||||
#[cfg(feature = "blocking")]
|
||||
pub(crate) fn into_io(e: Error) -> io::Error {
|
||||
e.into_io()
|
||||
}
|
||||
@@ -271,7 +266,7 @@ mod tests {
|
||||
let root = Error::new(Kind::Request, None::<Error>);
|
||||
assert!(root.source().is_none());
|
||||
|
||||
let link = super::response(root);
|
||||
let link = super::body(root);
|
||||
assert!(link.source().is_some());
|
||||
assert_send::<Error>();
|
||||
assert_sync::<Error>();
|
||||
@@ -287,7 +282,7 @@ mod tests {
|
||||
fn roundtrip_io_error() {
|
||||
let orig = super::request("orig");
|
||||
// Convert reqwest::Error into an io::Error...
|
||||
let io = super::into_io(orig);
|
||||
let io = orig.into_io();
|
||||
// Convert that io::Error back into a reqwest::Error...
|
||||
let err = super::decode_io(io);
|
||||
// It should have pulled out the original, not nested it...
|
||||
|
||||
@@ -156,6 +156,7 @@
|
||||
//! `native-tls` library to connect over HTTPS.
|
||||
//! - **default-tls-vendored**: Enables the `vendored` feature of `native-tls`.
|
||||
//! - **rustls-tls**: Provides TLS support via the `rustls` library.
|
||||
//! - **blocking**: Provides the [blocking][] client API.
|
||||
//! - **cookies**: Provides cookie session support.
|
||||
//!
|
||||
//!
|
||||
@@ -205,6 +206,7 @@ pub use self::tls::{Certificate, Identity};
|
||||
mod error;
|
||||
|
||||
mod async_impl;
|
||||
#[cfg(feature = "blocking")]
|
||||
pub mod blocking;
|
||||
mod connect;
|
||||
#[cfg(feature = "cookies")]
|
||||
|
||||
Reference in New Issue
Block a user