reqwest: Support multi-threaded tokio runtime

This commit is contained in:
Aode (Lion) 2022-04-25 11:03:00 -05:00
parent 02b85e55d8
commit 1573372778
3 changed files with 28 additions and 21 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "http-signature-normalization-reqwest"
description = "An HTTP Signatures library that leaves the signing to you"
version = "0.5.0"
version = "0.6.0"
authors = ["asonix <asonix@asonix.dog>"]
license-file = "LICENSE"
readme = "README.md"
@ -31,9 +31,14 @@ reqwest-middleware = { version = "0.1.2", optional = true }
sha2 = { version = "0.10", optional = true }
sha3 = { version = "0.10", optional = true }
thiserror = "1.0"
tokio = { version = "1", default-features = false, features = ["rt"], optional = true }
tokio = { version = "1", default-features = false, features = [
"rt",
], optional = true }
[dev-dependencies]
httpdate = "1.0.2"
pretty_env_logger = "0.4"
tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "macros"] }
tokio = { version = "1", default-features = false, features = [
"rt-multi-thread",
"macros",
] }

View file

@ -5,7 +5,7 @@ use httpdate::HttpDate;
use reqwest::{header::DATE, Client};
use sha2::{Digest, Sha256};
async fn request(config: Config) -> Result<(), Box<dyn std::error::Error>> {
async fn request(config: Config) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let digest = Sha256::new();
let client = Client::new();
@ -28,15 +28,17 @@ async fn request(config: Config) -> Result<(), Box<dyn std::error::Error>> {
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
std::env::set_var("RUST_LOG", "info");
pretty_env_logger::init();
tokio::spawn(async move {
let config = Config::default().require_header("accept");
request(config.clone()).await?;
request(config.mastodon_compat()).await?;
Ok(())
request(config.mastodon_compat()).await
})
.await?
}
#[derive(Debug, thiserror::Error)]

View file

@ -29,11 +29,11 @@ pub trait SignExt: Sign {
digest: D,
v: V,
f: F,
) -> Pin<Box<dyn Future<Output = Result<Request, E>>>>
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
where
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
E: From<SignError> + From<reqwest::Error>,
K: Display + 'static,
K: Display + Send + 'static,
D: DigestCreate + Send + 'static,
V: AsRef<[u8]> + Into<Body> + Send + 'static,
Self: Sized;
@ -45,11 +45,11 @@ pub trait SignExt: Sign {
digest: D,
v: V,
f: F,
) -> Pin<Box<dyn Future<Output = Result<Request, E>>>>
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
where
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
E: From<SignError> + From<reqwest::Error>,
K: Display + 'static,
K: Display + Send + 'static,
D: DigestCreate + Send + 'static,
V: AsRef<[u8]> + Into<Body> + Send + 'static,
Self: Sized;
@ -63,11 +63,11 @@ impl SignExt for RequestBuilder {
mut digest: D,
v: V,
f: F,
) -> Pin<Box<dyn Future<Output = Result<Request, E>>>>
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
where
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
E: From<SignError> + From<reqwest::Error>,
K: Display + 'static,
K: Display + Send + 'static,
D: DigestCreate + Send + 'static,
V: AsRef<[u8]> + Into<Body> + Send + 'static,
Self: Sized,
@ -97,11 +97,11 @@ impl SignExt for RequestBuilder {
mut digest: D,
v: V,
f: F,
) -> Pin<Box<dyn Future<Output = Result<Request, E>>>>
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
where
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
E: From<SignError> + From<reqwest::Error>,
K: Display + 'static,
K: Display + Send + 'static,
D: DigestCreate + Send + 'static,
V: AsRef<[u8]> + Into<Body> + Send + 'static,
Self: Sized,
@ -140,11 +140,11 @@ mod middleware {
mut digest: D,
v: V,
f: F,
) -> Pin<Box<dyn Future<Output = Result<Request, E>>>>
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
where
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
E: From<SignError> + From<reqwest::Error>,
K: Display + 'static,
K: Display + Send + 'static,
D: DigestCreate + Send + 'static,
V: AsRef<[u8]> + Into<Body> + Send + 'static,
Self: Sized,
@ -174,11 +174,11 @@ mod middleware {
mut digest: D,
v: V,
f: F,
) -> Pin<Box<dyn Future<Output = Result<Request, E>>>>
) -> Pin<Box<dyn Future<Output = Result<Request, E>> + Send>>
where
F: FnOnce(&str) -> Result<String, E> + Send + 'static,
E: From<SignError> + From<reqwest::Error>,
K: Display + 'static,
K: Display + Send + 'static,
D: DigestCreate + Send + 'static,
V: AsRef<[u8]> + Into<Body> + Send + 'static,
Self: Sized,