client: Remove isahc feature of ruma-client

This commit is contained in:
Ossi Herrala 2024-04-25 19:46:38 +03:00 committed by Jonas Platte
parent 770dce844e
commit 87950e9d40
9 changed files with 4 additions and 104 deletions

View File

@ -1,5 +1,9 @@
# [unreleased]
Breaking changes:
- Remove `isahc` feature
Improvements:
- Add `error_kind` accessor method to `Error<E, ruma_client_api::Error>`

View File

@ -22,7 +22,6 @@ client-api = ["dep:as_variant", "dep:ruma-client-api"]
hyper = ["dep:hyper"]
hyper-native-tls = ["hyper", "dep:hyper-tls"]
hyper-rustls = ["hyper", "dep:hyper-rustls"]
isahc = ["dep:isahc", "futures-lite"]
reqwest = ["dep:reqwest"]
reqwest-native-tls = ["reqwest", "reqwest?/native-tls"]
reqwest-native-tls-alpn = ["reqwest", "reqwest?/native-tls-alpn"]
@ -37,12 +36,10 @@ assign = { workspace = true }
async-stream = "0.3.0"
bytes = "1.0.1"
futures-core = "0.3.8"
futures-lite = { version = "1.11.3", optional = true }
http = { workspace = true }
hyper = { version = "0.14.2", optional = true, features = ["client", "http1", "http2", "tcp"] }
hyper-rustls = { version = "0.24.0", optional = true, default-features = false }
hyper-tls = { version = "0.5.0", optional = true }
isahc = { version = "1.3.1", optional = true }
reqwest = { version = "0.11.4", optional = true, default-features = false }
ruma-client-api = { workspace = true, optional = true, features = ["client"] }
ruma-common = { workspace = true, features = ["api"] }

View File

@ -13,8 +13,6 @@ use crate::{add_user_id_to_query, ResponseError, ResponseResult};
#[cfg(feature = "hyper")]
mod hyper;
#[cfg(feature = "isahc")]
mod isahc;
#[cfg(feature = "reqwest")]
mod reqwest;
@ -24,8 +22,6 @@ pub use self::hyper::Hyper;
pub use self::hyper::HyperNativeTls;
#[cfg(feature = "hyper-rustls")]
pub use self::hyper::HyperRustls;
#[cfg(feature = "isahc")]
pub use self::isahc::Isahc;
#[cfg(feature = "reqwest")]
pub use self::reqwest::Reqwest;

View File

@ -1,22 +0,0 @@
use futures_lite::AsyncReadExt;
use super::HttpClient;
/// The `isahc` crate's `HttpClient`.
pub type Isahc = isahc::HttpClient;
impl HttpClient for Isahc {
type RequestBody = Vec<u8>;
type ResponseBody = Vec<u8>;
type Error = isahc::Error;
async fn send_http_request(
&self,
req: http::Request<Vec<u8>>,
) -> Result<http::Response<Vec<u8>>, isahc::Error> {
let (head, mut body) = self.send_async(req).await?.into_parts();
let mut full_body = Vec::new();
body.read_to_end(&mut full_body).await?;
Ok(http::Response::from_parts(head, full_body))
}
}

View File

@ -84,7 +84,6 @@
//! * `hyper`
//! * `hyper-native-tls`
//! * `hyper-rustls`
//! * `isahc`
//! * `reqwest` if you use the `reqwest` library already, activate this feature and configure the
//! TLS backend on `reqwest` directly. If you want to use `reqwest` but don't depend on it
//! already, use one of the sub-features instead. For details on the meaning of these, see

View File

@ -28,7 +28,6 @@ state-res = ["dep:ruma-state-res"]
client-ext-client-api = ["client", "ruma-client?/client-api"]
client-hyper = ["client", "ruma-client?/hyper"]
client-hyper-native-tls = ["client", "ruma-client?/hyper-native-tls"]
client-isahc = ["client", "ruma-client?/isahc"]
client-reqwest = ["client", "ruma-client?/reqwest"]
client-reqwest-native-tls = ["client", "ruma-client?/reqwest-native-tls"]
client-reqwest-native-tls-vendored = ["client", "ruma-client?/reqwest-native-tls-vendored"]

View File

@ -1,12 +0,0 @@
[package]
name = "hello_isahc"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
ruma = { version = "0.9.4", path = "../../crates/ruma", features = ["client-api-c", "client-ext-client-api", "client-isahc", "rand"] }
anyhow = "1.0.37"
isahc = "1.3.1"
tokio = { version = "1.0.1", features = ["macros", "rt"] }

View File

@ -1,13 +0,0 @@
Same as the [hello_world](../hello_world) example, but using the
[isahc](https://crates.io/crates/isahc) HTTP client (a Rust wrapper around libcurl).
# Usage
You will need to use an existing account on a homeserver that allows login with
a password.
In this folder, you can run it with this command:
```shell
cargo run <homeserver_url> <username> <password> <room>
```

View File

@ -1,48 +0,0 @@
use std::{env, process::exit};
use ruma::{
api::client::{alias::get_alias, membership::join_room_by_id, message::send_message_event},
events::room::message::RoomMessageEventContent,
OwnedRoomAliasId, TransactionId,
};
async fn hello_world(
homeserver_url: String,
username: &str,
password: &str,
room_alias: OwnedRoomAliasId,
) -> anyhow::Result<()> {
let http_client = isahc::HttpClient::new()?;
let client =
ruma::Client::builder().homeserver_url(homeserver_url).http_client(http_client).await?;
client.log_in(username, password, None, Some("ruma-example-client")).await?;
let room_id = client.send_request(get_alias::v3::Request::new(room_alias)).await?.room_id;
client.send_request(join_room_by_id::v3::Request::new(room_id.clone())).await?;
client
.send_request(send_message_event::v3::Request::new(
room_id,
TransactionId::new(),
&RoomMessageEventContent::text_plain("Hello World!"),
)?)
.await?;
Ok(())
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
let (homeserver_url, username, password, room) =
match (env::args().nth(1), env::args().nth(2), env::args().nth(3), env::args().nth(4)) {
(Some(a), Some(b), Some(c), Some(d)) => (a, b, c, d),
_ => {
eprintln!(
"Usage: {} <homeserver_url> <username> <password> <room>",
env::args().next().unwrap()
);
exit(1)
}
};
hello_world(homeserver_url, &username, &password, room.try_into()?).await
}