|
@@ -353,32 +353,6 @@ pub struct Response(ResponseType, reqwest::Response);
|
|
#[derive(Debug)]
|
|
#[derive(Debug)]
|
|
pub struct Response(ResponseType, attohttpc::Response, Url);
|
|
pub struct Response(ResponseType, attohttpc::Response, Url);
|
|
|
|
|
|
-#[cfg(not(feature = "reqwest-client"))]
|
|
|
|
-struct AttohttpcByteReader(attohttpc::ResponseReader);
|
|
|
|
-
|
|
|
|
-#[cfg(not(feature = "reqwest-client"))]
|
|
|
|
-impl futures::Stream for AttohttpcByteReader {
|
|
|
|
- type Item = crate::api::Result<bytes::Bytes>;
|
|
|
|
-
|
|
|
|
- fn poll_next(
|
|
|
|
- mut self: std::pin::Pin<&mut Self>,
|
|
|
|
- _cx: &mut futures::task::Context<'_>,
|
|
|
|
- ) -> futures::task::Poll<Option<Self::Item>> {
|
|
|
|
- use std::io::Read;
|
|
|
|
- let mut buf = [0; 256];
|
|
|
|
- match self.0.read(&mut buf) {
|
|
|
|
- Ok(b) => {
|
|
|
|
- if b == 0 {
|
|
|
|
- futures::task::Poll::Ready(None)
|
|
|
|
- } else {
|
|
|
|
- futures::task::Poll::Ready(Some(Ok(buf[0..b].to_vec().into())))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- Err(_) => futures::task::Poll::Ready(None),
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
impl Response {
|
|
impl Response {
|
|
/// Get the [`StatusCode`] of this Response.
|
|
/// Get the [`StatusCode`] of this Response.
|
|
pub fn status(&self) -> StatusCode {
|
|
pub fn status(&self) -> StatusCode {
|
|
@@ -400,6 +374,13 @@ impl Response {
|
|
Ok(RawResponse { status, data })
|
|
Ok(RawResponse { status, data })
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #[cfg(not(feature = "reqwest-client"))]
|
|
|
|
+ #[allow(dead_code)]
|
|
|
|
+ pub(crate) fn reader(self) -> attohttpc::ResponseReader {
|
|
|
|
+ let (_, _, reader) = self.1.split();
|
|
|
|
+ reader
|
|
|
|
+ }
|
|
|
|
+
|
|
/// Convert the response into a Stream of [`bytes::Bytes`] from the body.
|
|
/// Convert the response into a Stream of [`bytes::Bytes`] from the body.
|
|
///
|
|
///
|
|
/// # Examples
|
|
/// # Examples
|
|
@@ -419,17 +400,13 @@ impl Response {
|
|
/// # Ok(())
|
|
/// # Ok(())
|
|
/// # }
|
|
/// # }
|
|
/// ```
|
|
/// ```
|
|
- pub fn bytes_stream(self) -> impl futures::Stream<Item = crate::api::Result<bytes::Bytes>> {
|
|
|
|
- #[cfg(not(feature = "reqwest-client"))]
|
|
|
|
- {
|
|
|
|
- let (_, _, reader) = self.1.split();
|
|
|
|
- AttohttpcByteReader(reader)
|
|
|
|
- }
|
|
|
|
- #[cfg(feature = "reqwest-client")]
|
|
|
|
- {
|
|
|
|
- use futures::StreamExt;
|
|
|
|
- self.1.bytes_stream().map(|res| res.map_err(Into::into))
|
|
|
|
- }
|
|
|
|
|
|
+ #[cfg(feature = "reqwest-client")]
|
|
|
|
+ #[allow(dead_code)]
|
|
|
|
+ pub(crate) fn bytes_stream(
|
|
|
|
+ self,
|
|
|
|
+ ) -> impl futures::Stream<Item = crate::api::Result<bytes::Bytes>> {
|
|
|
|
+ use futures::StreamExt;
|
|
|
|
+ self.1.bytes_stream().map(|res| res.map_err(Into::into))
|
|
}
|
|
}
|
|
|
|
|
|
/// Reads the response.
|
|
/// Reads the response.
|