Trait matrix_sdk::HttpSend [−][src]
pub trait HttpSend: AsyncTraitDeps {
fn send_request<'life0, 'async_trait>(
&'life0 self,
request: Request<Bytes>,
config: RequestConfig
) -> Pin<Box<dyn Future<Output = Result<Response<Bytes>, HttpError>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
}
Expand description
Abstraction around the http layer. The allows implementors to use different http libraries.
Required methods
The method abstracting sending request types and receiving response types.
This is called by the client every time it wants to send anything to a homeserver.
Arguments
-
request
- The http request that has been converted from a rumaRequest
. -
request_config
- The config used for this request.
Examples
use std::convert::TryFrom;
use matrix_sdk::{HttpSend, async_trait, HttpError, RequestConfig, bytes::Bytes};
#[derive(Debug)]
struct Client(reqwest::Client);
impl Client {
async fn response_to_http_response(
&self,
mut response: reqwest::Response,
) -> Result<http::Response<Bytes>, HttpError> {
// Convert the reqwest response to a http one.
todo!()
}
}
#[async_trait]
impl HttpSend for Client {
async fn send_request(
&self,
request: http::Request<Bytes>,
config: RequestConfig,
) -> Result<http::Response<Bytes>, HttpError> {
Ok(self
.response_to_http_response(
self.0
.execute(reqwest::Request::try_from(request)?)
.await?,
)
.await?)
}
}