2019-09-11 23:06:36 +00:00
|
|
|
use actix::System;
|
|
|
|
use actix_web::client::Client;
|
|
|
|
use futures::future::{lazy, Future};
|
|
|
|
use http_signature_normalization_actix::prelude::*;
|
2019-09-13 01:12:35 +00:00
|
|
|
use sha2::{Digest, Sha256};
|
2019-09-11 23:06:36 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
System::new("client-example")
|
|
|
|
.block_on(lazy(|| {
|
|
|
|
let config = Config::default();
|
2019-09-13 01:12:35 +00:00
|
|
|
let mut digest = Sha256::new();
|
2019-09-11 23:06:36 +00:00
|
|
|
|
|
|
|
Client::default()
|
2019-09-13 01:12:35 +00:00
|
|
|
.post("http://127.0.0.1:8010/")
|
2019-09-11 23:06:36 +00:00
|
|
|
.header("User-Agent", "Actix Web")
|
2019-09-13 01:12:35 +00:00
|
|
|
.authorization_signature_with_digest::<_, MyError, _, _, _>(
|
|
|
|
&config,
|
|
|
|
"my-key-id",
|
|
|
|
&mut digest,
|
|
|
|
"Hewwo owo",
|
|
|
|
|s| Ok(s.as_bytes().to_vec()),
|
|
|
|
)
|
2019-09-11 23:06:36 +00:00
|
|
|
.unwrap()
|
|
|
|
.send()
|
|
|
|
.map_err(|_| ())
|
|
|
|
.and_then(|mut res| res.body().map_err(|_| ()))
|
|
|
|
.map(|body| {
|
|
|
|
println!("{:?}", body);
|
|
|
|
})
|
|
|
|
}))
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum MyError {
|
|
|
|
Convert(ToStrError),
|
|
|
|
Header(InvalidHeaderValue),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ToStrError> for MyError {
|
|
|
|
fn from(e: ToStrError) -> Self {
|
|
|
|
MyError::Convert(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<InvalidHeaderValue> for MyError {
|
|
|
|
fn from(e: InvalidHeaderValue) -> Self {
|
|
|
|
MyError::Header(e)
|
|
|
|
}
|
|
|
|
}
|