matrix-sdk: Move the HttpSend trait into the http_client file.
parent
fe572017b1
commit
9a325a4505
|
@ -19,11 +19,22 @@ use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::{self, Debug},
|
fmt::{self, Debug},
|
||||||
|
future::Future,
|
||||||
path::Path,
|
path::Path,
|
||||||
result::Result as StdResult,
|
result::Result as StdResult,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use futures_timer::Delay as sleep;
|
||||||
|
use reqwest::header::{HeaderValue, InvalidHeaderValue};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
#[cfg(feature = "encryption")]
|
||||||
|
use tracing::{debug, warn};
|
||||||
|
use tracing::{error, info, instrument};
|
||||||
|
|
||||||
|
use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore};
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
use matrix_sdk_common::api::r0::to_device::send_event_to_device::Request as ToDeviceRequest;
|
use matrix_sdk_common::api::r0::to_device::send_event_to_device::Request as ToDeviceRequest;
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
|
@ -36,28 +47,17 @@ use matrix_sdk_common::{
|
||||||
FromHttpResponseError,
|
FromHttpResponseError,
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures_timer::Delay as sleep;
|
|
||||||
use std::future::Future;
|
|
||||||
#[cfg(feature = "encryption")]
|
|
||||||
use tracing::{debug, warn};
|
|
||||||
use tracing::{error, info, instrument};
|
|
||||||
|
|
||||||
use reqwest::header::{HeaderValue, InvalidHeaderValue};
|
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
api,
|
||||||
events::{room::message::MessageEventContent, EventType},
|
events::{room::message::MessageEventContent, EventType},
|
||||||
http_client::DefaultHttpClient,
|
http_client::{DefaultHttpClient, HttpClient, HttpSend},
|
||||||
identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId},
|
identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId},
|
||||||
Endpoint, HttpSend,
|
Endpoint, EventEmitter, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
use crate::{identifiers::DeviceId, sas::Sas};
|
use crate::{identifiers::DeviceId, sas::Sas};
|
||||||
|
|
||||||
use crate::{api, http_client::HttpClient, EventEmitter, Result};
|
|
||||||
use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore};
|
|
||||||
|
|
||||||
const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
|
const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
|
|
||||||
/// An async/await enabled Matrix client.
|
/// An async/await enabled Matrix client.
|
||||||
|
|
|
@ -12,16 +12,57 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::{convert::TryFrom, sync::Arc};
|
use std::{convert::TryFrom, fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
use http::{HeaderValue, Method as HttpMethod, Response as HttpResponse};
|
use http::{HeaderValue, Method as HttpMethod, Response as HttpResponse};
|
||||||
use matrix_sdk_common::{locks::RwLock, FromHttpResponseError};
|
|
||||||
use matrix_sdk_common_macros::async_trait;
|
|
||||||
use reqwest::{Client, Response};
|
use reqwest::{Client, Response};
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{ClientConfig, Endpoint, Error, HttpSend, Result, Session};
|
use matrix_sdk_common::{locks::RwLock, FromHttpResponseError};
|
||||||
|
use matrix_sdk_common_macros::async_trait;
|
||||||
|
|
||||||
|
use crate::{ClientConfig, Endpoint, Error, Result, Session};
|
||||||
|
|
||||||
|
/// Abstraction around the http layer. The allows implementors to use different
|
||||||
|
/// http libraries.
|
||||||
|
#[async_trait]
|
||||||
|
pub trait HttpSend: Sync + Send + Debug {
|
||||||
|
/// 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`.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A `reqwest::Response` that will be converted to a ruma `Response` in the `Client`.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// use matrix_sdk::HttpSend;
|
||||||
|
/// use matrix_sdk_common_macros::async_trait;
|
||||||
|
/// use reqwest::Response;
|
||||||
|
///
|
||||||
|
/// #[derive(Debug)]
|
||||||
|
/// struct TestSend;
|
||||||
|
///
|
||||||
|
/// impl HttpSend for TestSend {
|
||||||
|
/// async fn send_request(&self, request: http::Request<Vec<u8>>) -> Result<Response>
|
||||||
|
/// // send the request somehow
|
||||||
|
/// let response = send(request, method, homeserver).await?;
|
||||||
|
///
|
||||||
|
/// // reqwest can convert to and from `http::Response` types.
|
||||||
|
/// Ok(reqwest::Response::from(response))
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
async fn send_request(&self, request: http::Request<Vec<u8>>) -> Result<Response>;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct HttpClient {
|
pub(crate) struct HttpClient {
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
use std::fmt::Debug;
|
|
||||||
|
|
||||||
use matrix_sdk_common_macros::async_trait;
|
|
||||||
use reqwest::Response;
|
|
||||||
|
|
||||||
use crate::Result;
|
|
||||||
|
|
||||||
/// Abstraction around the http layer. The allows implementors to use different
|
|
||||||
/// http libraries.
|
|
||||||
#[async_trait]
|
|
||||||
pub trait HttpSend: Sync + Send + Debug {
|
|
||||||
/// 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`.
|
|
||||||
///
|
|
||||||
/// # Returns
|
|
||||||
///
|
|
||||||
/// A `reqwest::Response` that will be converted to a ruma `Response` in the `Client`.
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// ```ignore
|
|
||||||
/// use matrix_sdk::HttpSend;
|
|
||||||
/// use matrix_sdk_common_macros::async_trait;
|
|
||||||
/// use reqwest::Response;
|
|
||||||
///
|
|
||||||
/// #[derive(Debug)]
|
|
||||||
/// struct TestSend;
|
|
||||||
///
|
|
||||||
/// impl HttpSend for TestSend {
|
|
||||||
/// async fn send_request(&self, request: http::Request<Vec<u8>>) -> Result<Response>
|
|
||||||
/// // send the request somehow
|
|
||||||
/// let response = send(request, method, homeserver).await?;
|
|
||||||
///
|
|
||||||
/// // reqwest can convert to and from `http::Response` types.
|
|
||||||
/// Ok(reqwest::Response::from(response))
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
async fn send_request(&self, request: http::Request<Vec<u8>>) -> Result<Response>;
|
|
||||||
}
|
|
|
@ -51,7 +51,6 @@ pub use reqwest::header::InvalidHeaderValue;
|
||||||
mod client;
|
mod client;
|
||||||
mod error;
|
mod error;
|
||||||
mod http_client;
|
mod http_client;
|
||||||
mod http_send;
|
|
||||||
mod request_builder;
|
mod request_builder;
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
|
@ -59,7 +58,7 @@ mod sas;
|
||||||
|
|
||||||
pub use client::{Client, ClientConfig, SyncSettings};
|
pub use client::{Client, ClientConfig, SyncSettings};
|
||||||
pub use error::{Error, Result};
|
pub use error::{Error, Result};
|
||||||
pub use http_send::HttpSend;
|
pub use http_client::HttpSend;
|
||||||
pub use request_builder::{
|
pub use request_builder::{
|
||||||
MessagesRequestBuilder, RegistrationBuilder, RoomBuilder, RoomListFilterBuilder,
|
MessagesRequestBuilder, RegistrationBuilder, RoomBuilder, RoomListFilterBuilder,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue