2023-08-17 17:34:51 +00:00
|
|
|
use http_signature_normalization_reqwest::{digest::ring::Sha256, prelude::*};
|
2022-11-22 16:15:14 +00:00
|
|
|
use reqwest::{
|
2022-11-23 00:12:41 +00:00
|
|
|
header::{ACCEPT, USER_AGENT},
|
2022-11-22 16:15:14 +00:00
|
|
|
Client,
|
|
|
|
};
|
2020-09-29 23:57:59 +00:00
|
|
|
|
2022-04-25 16:03:00 +00:00
|
|
|
async fn request(config: Config) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
2020-09-29 23:57:59 +00:00
|
|
|
let digest = Sha256::new();
|
|
|
|
|
2021-12-05 22:45:37 +00:00
|
|
|
let client = Client::new();
|
|
|
|
|
|
|
|
let request = client
|
2020-09-29 23:57:59 +00:00
|
|
|
.post("http://127.0.0.1:8010/")
|
2022-11-22 16:15:14 +00:00
|
|
|
.header(USER_AGENT, "Reqwest")
|
|
|
|
.header(ACCEPT, "text/plain")
|
2020-09-29 23:57:59 +00:00
|
|
|
.signature_with_digest(config, "my-key-id", digest, "Hewwo-owo", |s| {
|
|
|
|
println!("Signing String\n{}", s);
|
|
|
|
Ok(base64::encode(s)) as Result<_, MyError>
|
|
|
|
})
|
|
|
|
.await?;
|
|
|
|
|
2021-12-05 22:45:37 +00:00
|
|
|
let body = client.execute(request).await?.bytes().await?;
|
2020-09-29 23:57:59 +00:00
|
|
|
|
|
|
|
println!("{:?}", body);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
2022-04-25 16:03:00 +00:00
|
|
|
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
2020-09-29 23:57:59 +00:00
|
|
|
std::env::set_var("RUST_LOG", "info");
|
|
|
|
pretty_env_logger::init();
|
|
|
|
|
2022-04-25 16:03:00 +00:00
|
|
|
tokio::spawn(async move {
|
|
|
|
let config = Config::default().require_header("accept");
|
2020-09-29 23:57:59 +00:00
|
|
|
|
2022-04-25 16:03:00 +00:00
|
|
|
request(config.clone()).await?;
|
|
|
|
request(config.mastodon_compat()).await
|
|
|
|
})
|
|
|
|
.await?
|
2020-09-29 23:57:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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),
|
|
|
|
}
|