2019-09-11 23:06:36 +00:00
|
|
|
use actix::System;
|
|
|
|
use actix_web::client::Client;
|
2019-09-13 01:29:24 +00:00
|
|
|
use failure::Fail;
|
2019-09-11 23:06:36 +00:00
|
|
|
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 23:07:44 +00:00
|
|
|
.authorization_signature_with_digest(
|
2019-09-13 01:12:35 +00:00
|
|
|
&config,
|
|
|
|
"my-key-id",
|
|
|
|
&mut digest,
|
2019-09-13 22:55:51 +00:00
|
|
|
"Hewwo-owo",
|
2019-09-13 23:07:44 +00:00
|
|
|
|s| Ok(base64::encode(s)) as Result<_, MyError>,
|
2019-09-13 01:12:35 +00:00
|
|
|
)
|
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();
|
|
|
|
}
|
|
|
|
|
2019-09-13 01:29:24 +00:00
|
|
|
#[derive(Debug, Fail)]
|
2019-09-11 23:06:36 +00:00
|
|
|
pub enum MyError {
|
2019-09-13 01:29:24 +00:00
|
|
|
#[fail(display = "Failed to read header, {}", _0)]
|
|
|
|
Convert(#[cause] ToStrError),
|
|
|
|
|
|
|
|
#[fail(display = "Failed to create header, {}", _0)]
|
|
|
|
Header(#[cause] InvalidHeaderValue),
|
2019-09-11 23:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|