ReqwestClient

Struct ReqwestClient 

Source
pub struct ReqwestClient<Crypto> { /* private fields */ }
Expand description

A Repo and Deliver type backed by reqwest

This client is generic over it’s Cryptography. It signs it’s requests with HTTP Signatures, and computes digests of it’s request bodies.

use apub_reqwest::{ReqwestClient, SignatureConfig};
use apub_rustcrypto::Rustcrypto;
use reqwest_middleware::ClientBuilder;
use rsa::RsaPrivateKey;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let private_key = RsaPrivateKey::new(&mut rand::thread_rng(), 1024)?;
    let crypto = Rustcrypto::new("key-id".to_string(), private_key);
    let signature_config = SignatureConfig::default();

    let client = reqwest::Client::new();
    let client = ClientBuilder::new(client).build();

    let reqwest_client = ReqwestClient::new(client, signature_config, &crypto);
    Ok(())
}

Implementations§

Source§

impl<Crypto> ReqwestClient<Crypto>
where Crypto: PrivateKey, <<Crypto as PrivateKey>::Signer as Sign>::Error: Error,

Source

pub fn new( client: ClientWithMiddleware, config: SignatureConfig, crypto: Crypto, ) -> Self

Create a new Client & Repo implementation backed by the reqwest client

Trait Implementations§

Source§

impl<Crypto> Deliver for ReqwestClient<Crypto>
where Crypto: DigestFactory + PrivateKey + Send + Sync, <Crypto as DigestFactory>::Digest: DigestBuilder + Clone, <<Crypto as PrivateKey>::Signer as Sign>::Error: Error,

Source§

type Error = ReqwestError<<<Crypto as PrivateKey>::Signer as Sign>::Error>

Errors produced by the client
Source§

fn deliver<'life0, 'life1, 'life2, 'async_trait, T, S>( &'life0 self, inbox: &'life1 Url, activity: &'life2 T, session: S, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + 'async_trait>>
where T: 'async_trait + Serialize, S: 'async_trait + Session, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Deliver the activity to the inbox
Source§

impl<Crypto> Repo for ReqwestClient<Crypto>
where Crypto: PrivateKey + Send + Sync, <<Crypto as PrivateKey>::Signer as Sign>::Error: Error,

Source§

type Error = ReqwestError<<<Crypto as PrivateKey>::Signer as Sign>::Error>

The Error produced by fetching an object
Source§

fn fetch<'life0, 'async_trait, D, S>( &'life0 self, id: D, session: S, ) -> Pin<Box<dyn Future<Output = Result<Option<D::Output>, Self::Error>> + 'async_trait>>
where D: 'async_trait + Dereference, S: 'async_trait + Session, Self: 'async_trait, 'life0: 'async_trait,

Fetch the object from the repository

Auto Trait Implementations§

§

impl<Crypto> Freeze for ReqwestClient<Crypto>
where Crypto: Freeze,

§

impl<Crypto> !RefUnwindSafe for ReqwestClient<Crypto>

§

impl<Crypto> Send for ReqwestClient<Crypto>
where Crypto: Send,

§

impl<Crypto> Sync for ReqwestClient<Crypto>
where Crypto: Sync,

§

impl<Crypto> Unpin for ReqwestClient<Crypto>
where Crypto: Unpin,

§

impl<Crypto> !UnwindSafe for ReqwestClient<Crypto>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,