mirror of
https://git.asonix.dog/asonix/http-signature-normalization.git
synced 2024-11-29 04:41:00 +00:00
133e081740
Update actix library with new methods Build reqwest client with feature parity to actix client
51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use http_signature_normalization_reqwest::prelude::*;
|
|
use reqwest::{header::DATE, Client};
|
|
use sha2::{Digest, Sha256};
|
|
use time::OffsetDateTime;
|
|
|
|
async fn request(config: Config) -> Result<(), Box<dyn std::error::Error>> {
|
|
let digest = Sha256::new();
|
|
|
|
let response = Client::new()
|
|
.post("http://127.0.0.1:8010/")
|
|
.header("User-Agent", "Reqwest")
|
|
.header("Accept", "text/plain")
|
|
.header(
|
|
DATE,
|
|
OffsetDateTime::now_utc().format("%a, %d %b %Y %H:%M:%S GMT"),
|
|
)
|
|
.signature_with_digest(config, "my-key-id", digest, "Hewwo-owo", |s| {
|
|
println!("Signing String\n{}", s);
|
|
Ok(base64::encode(s)) as Result<_, MyError>
|
|
})
|
|
.await?;
|
|
|
|
let body = response.bytes().await.map_err(MyError::Body)?;
|
|
|
|
println!("{:?}", body);
|
|
Ok(())
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
std::env::set_var("RUST_LOG", "info");
|
|
pretty_env_logger::init();
|
|
|
|
let config = Config::default().require_header("accept");
|
|
|
|
request(config.clone()).await?;
|
|
request(config.mastodon_compat()).await?;
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum MyError {
|
|
#[error("Failed to create signing string, {0}")]
|
|
Convert(#[from] SignError),
|
|
|
|
#[error("Failed to send request")]
|
|
SendRequest(#[from] reqwest::Error),
|
|
|
|
#[error("Failed to retrieve request body")]
|
|
Body(reqwest::Error),
|
|
}
|