mirror of
https://git.asonix.dog/asonix/http-signature-normalization.git
synced 2024-11-13 05:01:17 +00:00
45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
|
use actix::System;
|
||
|
use actix_web::client::Client;
|
||
|
use futures::future::{lazy, Future};
|
||
|
use http_signature_normalization_actix::prelude::*;
|
||
|
|
||
|
fn main() {
|
||
|
System::new("client-example")
|
||
|
.block_on(lazy(|| {
|
||
|
let config = Config::default();
|
||
|
|
||
|
Client::default()
|
||
|
.get("http://127.0.0.1:8010/")
|
||
|
.header("User-Agent", "Actix Web")
|
||
|
.authorization_signature::<_, MyError, _>(&config, "my-key-id", |s| {
|
||
|
Ok(s.as_bytes().to_vec())
|
||
|
})
|
||
|
.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)
|
||
|
}
|
||
|
}
|