Update dependencies, release 0.3.0-beta.2
This commit is contained in:
parent
fcd1b204eb
commit
7208e66dff
20
Cargo.toml
20
Cargo.toml
@ -10,25 +10,27 @@ license = "MIT"
|
||||
name = "ruma-client"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/ruma/ruma-client"
|
||||
version = "0.3.0-beta.1"
|
||||
version = "0.3.0-beta.2"
|
||||
|
||||
[dependencies]
|
||||
futures-preview = "=0.3.0-alpha.19"
|
||||
http = "0.1.20"
|
||||
hyper = { version = "=0.13.0-alpha.4", features = ["unstable-stream"] }
|
||||
hyper-tls = { version = "=0.4.0-alpha.4", optional = true }
|
||||
ruma-api = "0.12.0-alpha.1"
|
||||
ruma-client-api = "0.5.0-alpha.1"
|
||||
futures-core = "0.3.1"
|
||||
futures-util = "0.3.1"
|
||||
http = "0.2.0"
|
||||
hyper = "0.13.0"
|
||||
hyper-tls = { version = "0.4.0", optional = true }
|
||||
ruma-api = "0.12.0"
|
||||
ruma-client-api = "0.5.0"
|
||||
ruma-events = "0.15.1"
|
||||
ruma-identifiers = "0.14.0"
|
||||
native-tls = { version = "0.2.3", optional = true }
|
||||
serde = { version = "1.0.103", features = ["derive"] }
|
||||
serde_json = "1.0.42"
|
||||
serde_json = "1.0.44"
|
||||
serde_urlencoded = "0.6.1"
|
||||
tokio = "0.2.4"
|
||||
url = "2.1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = "=0.2.0-alpha.6"
|
||||
tokio = { version = "0.2.4", features = ["macros"] }
|
||||
|
||||
[features]
|
||||
default = ["tls"]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::{env, process::exit};
|
||||
|
||||
use futures::stream::{StreamExt as _, TryStreamExt as _};
|
||||
use futures_util::stream::{StreamExt as _, TryStreamExt as _};
|
||||
use ruma_client::{
|
||||
self,
|
||||
events::{
|
||||
|
37
src/lib.rs
37
src/lib.rs
@ -88,20 +88,22 @@ use std::{
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use futures::{
|
||||
use futures_core::{
|
||||
future::Future,
|
||||
stream::{self, Stream, TryStream, TryStreamExt as _},
|
||||
stream::{Stream, TryStream},
|
||||
};
|
||||
use futures_util::stream;
|
||||
use http::Response as HttpResponse;
|
||||
use hyper::{
|
||||
client::{connect::Connect, HttpConnector},
|
||||
Client as HyperClient, Uri,
|
||||
client::connect::Connection, client::HttpConnector, service::Service, Client as HyperClient,
|
||||
Uri,
|
||||
};
|
||||
#[cfg(feature = "hyper-tls")]
|
||||
use hyper_tls::HttpsConnector;
|
||||
#[cfg(feature = "hyper-tls")]
|
||||
use native_tls::Error as NativeTlsError;
|
||||
use ruma_api::{Endpoint, Outgoing};
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use url::Url;
|
||||
|
||||
use crate::error::InnerError;
|
||||
@ -118,14 +120,11 @@ mod session;
|
||||
|
||||
/// A client for the Matrix client-server API.
|
||||
#[derive(Debug)]
|
||||
pub struct Client<C: Connect>(Arc<ClientData<C>>);
|
||||
pub struct Client<C>(Arc<ClientData<C>>);
|
||||
|
||||
/// Data contained in Client's Rc
|
||||
#[derive(Debug)]
|
||||
struct ClientData<C>
|
||||
where
|
||||
C: Connect,
|
||||
{
|
||||
struct ClientData<C> {
|
||||
/// The URL of the homeserver to connect to.
|
||||
homeserver_url: Url,
|
||||
/// The underlying HTTP client.
|
||||
@ -167,7 +166,7 @@ pub type HttpsClient = Client<HttpsConnector<HttpConnector>>;
|
||||
impl HttpsClient {
|
||||
/// Creates a new client for making HTTPS requests to the given homeserver.
|
||||
pub fn https(homeserver_url: Url, session: Option<Session>) -> Result<Self, NativeTlsError> {
|
||||
let connector = HttpsConnector::new()?;
|
||||
let connector = HttpsConnector::new();
|
||||
|
||||
Ok(Self(Arc::new(ClientData {
|
||||
homeserver_url,
|
||||
@ -179,7 +178,10 @@ impl HttpsClient {
|
||||
|
||||
impl<C> Client<C>
|
||||
where
|
||||
C: Connect + 'static,
|
||||
C: Service<Uri> + Clone + Send + Sync + 'static,
|
||||
C::Response: Connection + AsyncRead + AsyncWrite + Send + Unpin + 'static,
|
||||
C::Future: Send + Unpin + 'static,
|
||||
C::Error: Into<Box<dyn std::error::Error + Send + Sync + 'static>>,
|
||||
{
|
||||
/// Creates a new client using the given `hyper::Client`.
|
||||
///
|
||||
@ -375,9 +377,9 @@ where
|
||||
{
|
||||
let client = self.0.clone();
|
||||
|
||||
async move {
|
||||
let mut url = client.homeserver_url.clone();
|
||||
let mut url = client.homeserver_url.clone();
|
||||
|
||||
async move {
|
||||
let mut hyper_request = request.try_into()?.map(hyper::Body::from);
|
||||
|
||||
{
|
||||
@ -400,8 +402,11 @@ where
|
||||
|
||||
let hyper_response = client.hyper.request(hyper_request).await?;
|
||||
let (head, body) = hyper_response.into_parts();
|
||||
let full_response =
|
||||
HttpResponse::from_parts(head, body.try_concat().await?.as_ref().to_owned());
|
||||
|
||||
// FIXME: We read the reponse into a contiguous buffer here (not actually required for
|
||||
// deserialization) and then copy the whole thing to convert from Bytes to Vec<u8>.
|
||||
let full_body = hyper::body::to_bytes(body).await?;
|
||||
let full_response = HttpResponse::from_parts(head, full_body.as_ref().to_owned());
|
||||
|
||||
Ok(<Request::Response as Outgoing>::Incoming::try_from(
|
||||
full_response,
|
||||
@ -410,7 +415,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: Connect> Clone for Client<C> {
|
||||
impl<C> Clone for Client<C> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user