diff --git a/matrix_sdk/Cargo.toml b/matrix_sdk/Cargo.toml index ed531c76..d019cc82 100644 --- a/matrix_sdk/Cargo.toml +++ b/matrix_sdk/Cargo.toml @@ -40,6 +40,7 @@ url = "2.2.0" zeroize = "1.2.0" mime = "0.3.16" rand = { version = "0.8.2", optional = true } +bytes = "1.0.1" matrix-sdk-common = { version = "0.2.0", path = "../matrix_sdk_common" } diff --git a/matrix_sdk/src/http_client.rs b/matrix_sdk/src/http_client.rs index 1eab2dd1..81c1dab9 100644 --- a/matrix_sdk/src/http_client.rs +++ b/matrix_sdk/src/http_client.rs @@ -30,7 +30,7 @@ use matrix_sdk_common::{ FromHttpResponseError, IncomingResponse, }; -use crate::{error::HttpError, ClientConfig, OutgoingRequest, RequestConfig, Session}; +use crate::{error::HttpError, Bytes, ClientConfig, OutgoingRequest, RequestConfig, Session}; /// Abstraction around the http layer. The allows implementors to use different /// http libraries. @@ -51,7 +51,7 @@ pub trait HttpSend: AsyncTraitDeps { /// /// ``` /// use std::convert::TryFrom; - /// use matrix_sdk::{HttpSend, async_trait, HttpError, RequestConfig}; + /// use matrix_sdk::{HttpSend, async_trait, HttpError, RequestConfig, Bytes}; /// /// #[derive(Debug)] /// struct Client(reqwest::Client); @@ -60,7 +60,7 @@ pub trait HttpSend: AsyncTraitDeps { /// async fn response_to_http_response( /// &self, /// mut response: reqwest::Response, - /// ) -> Result>, HttpError> { + /// ) -> Result, HttpError> { /// // Convert the reqwest response to a http one. /// todo!() /// } @@ -72,7 +72,7 @@ pub trait HttpSend: AsyncTraitDeps { /// &self, /// request: http::Request>, /// config: RequestConfig, - /// ) -> Result>, HttpError> { + /// ) -> Result, HttpError> { /// Ok(self /// .response_to_http_response( /// self.0 @@ -87,7 +87,7 @@ pub trait HttpSend: AsyncTraitDeps { &self, request: http::Request>, config: RequestConfig, - ) -> Result>, HttpError>; + ) -> Result, HttpError>; } #[derive(Clone, Debug)] @@ -104,7 +104,7 @@ impl HttpClient { request: Request, session: Arc>>, config: Option, - ) -> Result>, HttpError> { + ) -> Result, HttpError> { let request = { let read_guard; let access_token = match Request::METADATA.authentication { @@ -205,7 +205,7 @@ pub(crate) fn client_with_config(config: &ClientConfig) -> Result Result>, reqwest::Error> { +) -> Result, reqwest::Error> { let status = response.status(); let mut http_builder = HttpResponse::builder().status(status); @@ -219,7 +219,7 @@ async fn response_to_http_response( } } - let body = response.bytes().await?.as_ref().to_owned(); + let body = response.bytes().await?; Ok(http_builder .body(body) @@ -231,7 +231,7 @@ async fn send_request( client: &Client, request: http::Request>, _: RequestConfig, -) -> Result>, HttpError> { +) -> Result, HttpError> { let request = reqwest::Request::try_from(request)?; let response = client.execute(request).await?; @@ -243,7 +243,7 @@ async fn send_request( client: &Client, request: http::Request>, config: RequestConfig, -) -> Result>, HttpError> { +) -> Result, HttpError> { let mut backoff = ExponentialBackoff::default(); let mut request = reqwest::Request::try_from(request)?; let retry_limit = config.retry_limit; @@ -305,7 +305,7 @@ impl HttpSend for Client { &self, request: http::Request>, config: RequestConfig, - ) -> Result>, HttpError> { + ) -> Result, HttpError> { send_request(&self, request, config).await } } diff --git a/matrix_sdk/src/lib.rs b/matrix_sdk/src/lib.rs index f7ac4928..cbfbaa05 100644 --- a/matrix_sdk/src/lib.rs +++ b/matrix_sdk/src/lib.rs @@ -76,6 +76,7 @@ pub use matrix_sdk_base::{ Session, StateChanges, StoreError, }; +pub use bytes::Bytes; pub use matrix_sdk_common::*; pub use reqwest;