diff --git a/Cargo.toml b/Cargo.toml index 1c5bd53c..c87d7664 100644 --- a/Cargo.toml +++ b/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"] diff --git a/examples/message_log.rs b/examples/message_log.rs index 9b70ef07..4be27514 100644 --- a/examples/message_log.rs +++ b/examples/message_log.rs @@ -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::{ diff --git a/src/lib.rs b/src/lib.rs index a76132e1..8b4622ac 100644 --- a/src/lib.rs +++ b/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(Arc>); +pub struct Client(Arc>); /// Data contained in Client's Rc #[derive(Debug)] -struct ClientData -where - C: Connect, -{ +struct ClientData { /// The URL of the homeserver to connect to. homeserver_url: Url, /// The underlying HTTP client. @@ -167,7 +166,7 @@ pub type HttpsClient = Client>; impl HttpsClient { /// Creates a new client for making HTTPS requests to the given homeserver. pub fn https(homeserver_url: Url, session: Option) -> Result { - let connector = HttpsConnector::new()?; + let connector = HttpsConnector::new(); Ok(Self(Arc::new(ClientData { homeserver_url, @@ -179,7 +178,10 @@ impl HttpsClient { impl Client where - C: Connect + 'static, + C: Service + Clone + Send + Sync + 'static, + C::Response: Connection + AsyncRead + AsyncWrite + Send + Unpin + 'static, + C::Future: Send + Unpin + 'static, + C::Error: Into>, { /// 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. + let full_body = hyper::body::to_bytes(body).await?; + let full_response = HttpResponse::from_parts(head, full_body.as_ref().to_owned()); Ok(::Incoming::try_from( full_response, @@ -410,7 +415,7 @@ where } } -impl Clone for Client { +impl Clone for Client { fn clone(&self) -> Self { Self(self.0.clone()) }