[][src]Trait matrix_sdk::HttpSend

pub trait HttpSend: Sync + Send + Debug {
#[must_use]    pub fn send_request<'life0, 'async_trait>(
        &'life0 self,
        request: Request<Vec<u8>>
    ) -> Pin<Box<dyn Future<Output = Result<Response<Vec<u8>>>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
; }

Abstraction around the http layer. The allows implementors to use different http libraries.

Required methods

#[must_use]pub fn send_request<'life0, 'async_trait>(
    &'life0 self,
    request: Request<Vec<u8>>
) -> Pin<Box<dyn Future<Output = Result<Response<Vec<u8>>>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 
[src]

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 ruma Request.

Examples

use std::convert::TryFrom;
use matrix_sdk::{HttpSend, Result, async_trait};

#[derive(Debug)]
struct Client(reqwest::Client);

impl Client {
    async fn response_to_http_response(
        &self,
        mut response: reqwest::Response,
    ) -> Result<http::Response<Vec<u8>>> {
        // Convert the reqwest response to a http one.
        todo!()
    }
}

#[async_trait]
impl HttpSend for Client {
    async fn send_request(&self, request: http::Request<Vec<u8>>) -> Result<http::Response<Vec<u8>>> {
        Ok(self
            .response_to_http_response(
                self.0
                    .execute(reqwest::Request::try_from(request)?)
                    .await?,
            )
            .await?)
    }
}
Loading content...

Implementations on Foreign Types

impl HttpSend for Client[src]

Loading content...

Implementors

Loading content...