Struct WebFingerRequest

Source
pub struct WebFingerRequest {
    pub resource: Uri,
    pub host: String,
    pub rels: Vec<Rel>,
}
Expand description

A WebFinger request.

This represents the request portion of a WebFinger query that can be executed against a WebFinger server.

See RFC 7033 Section 4 for more information.

§Examples

use webfinger_rs::WebFingerRequest;

let request = WebFingerRequest::builder("acct:carol@example.com")?
    .host("example.com")
    .rel("http://webfinger.net/rel/profile-page")
    .build();

To execute the query, enable the reqwest feature and call query.execute().

let response = request.execute_reqwest().await?;

Request can be used as an Axum extractor as it implements axum::extract::FromRequestParts.

use webfinger_rs::{WebFingerRequest, WebFingerResponse};

async fn handler(request: WebFingerRequest) -> WebFingerResponse {
    // ... handle the request ...
}

Fields§

§resource: Uri

Query target.

This is the URI of the resource to query. It will be stored in the resource query parameter.

TODO: This could be a newtype that represents the resource and makes it easier to extract the values / parse into the right types (e.g. acct: URIs).

§host: String

The host to query

TODO: this might be better as an Option<Uri> or Option<Host> or something similar. When the resource has a host part, it should be used unless this field is set.

§rels: Vec<Rel>

Link relation types

This is a list of link relation types to query for. Each link relation type will be stored in a rel query parameter.

Implementations§

Source§

impl WebFingerRequest

Source

pub async fn execute_reqwest(&self) -> Result<WebFingerResponse, Error>

Available on crate feature reqwest only.

Executes the WebFinger request.

§Examples
use webfinger_rs::WebFingerRequest;

let query = WebFingerRequest::builder("acct:carol@example.com")?
    .host("example.com")
    .rel("http://webfinger.net/rel/profile-page")
    .build();
let response = query.execute_reqwest().await?;
Examples found in repository?
examples/client.rs (line 9)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    let request = WebFingerRequest::builder("acct:carol@example.com")?
6        .host("example.com")
7        .rel("http://webfinger.net/rel/profile-page")
8        .build();
9    let response = request.execute_reqwest().await?;
10    dbg!(response);
11    Ok(())
12}
Source

pub async fn execute_reqwest_with_client( &self, client: &Client, ) -> Result<WebFingerResponse, Error>

Available on crate feature reqwest only.

Executes the WebFinger request with a custom reqwest client.

Source

pub fn try_into_reqwest(&self) -> Result<Request, Error>

Available on crate feature reqwest only.

Converts the WebFinger request into a reqwest request.

Source§

impl Request

Source

pub fn new(resource: Uri) -> Self

Creates a new WebFinger request.

Source

pub fn builder<U>(uri: U) -> Result<Builder, Error>
where Uri: TryFrom<U>, <Uri as TryFrom<U>>::Error: Into<Error>,

Creates a new Builder for a WebFinger request.

Examples found in repository?
examples/client.rs (line 5)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    let request = WebFingerRequest::builder("acct:carol@example.com")?
6        .host("example.com")
7        .rel("http://webfinger.net/rel/profile-page")
8        .build();
9    let response = request.execute_reqwest().await?;
10    dbg!(response);
11    Ok(())
12}

Trait Implementations§

Source§

impl Clone for Request

Source§

fn clone(&self) -> Request

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Request

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromRequest for WebFingerRequest

Available on crate feature actix only.
Source§

type Error = Error

The associated error which can be returned.
Source§

type Future = Pin<Box<dyn Future<Output = Result<Request, <Request as FromRequest>::Error>> + Send>>

Future that resolves to a Self. Read more
Source§

fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future

Create a Self from request parts asynchronously.
Source§

fn extract(req: &HttpRequest) -> Self::Future

Create a Self from request head asynchronously. Read more
Source§

impl<S: Send + Sync> FromRequestParts<S> for WebFingerRequest

Available on crate feature axum only.
Source§

async fn from_request_parts( parts: &mut Parts, state: &S, ) -> Result<Self, Self::Rejection>

Extracts a WebFingerRequest from the request parts.

§Errors
  • If the request is missing the Host header, it will return a Bad Request response with the message “missing host”.

  • If the resource query parameter is missing or invalid, it will return a Bad Request response with the message “invalid resource: {error}”.

  • If the rel query parameter is invalid, it will return a Bad Request response with the message “invalid query string: {error}”.

See the axum example for more information.

§Example
use axum::response::IntoResponse;
use webfinger_rs::WebFingerRequest;

async fn handler(request: WebFingerRequest) -> impl IntoResponse {
    let WebFingerRequest {
        host,
        resource,
        rels,
    } = request;
    // ... your code to handle the webfinger request ...
}
Source§

type Rejection = Rejection

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

impl PartialEq for Request

Source§

fn eq(&self, other: &Request) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Request

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&Request> for PathAndQuery

Source§

type Error = InvalidUri

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

fn try_from(query: &WebFingerRequest) -> Result<PathAndQuery, InvalidUri>

Performs the conversion.
Source§

impl TryFrom<&Request> for Request

Available on crate feature reqwest only.
Source§

type Error = Error

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

fn try_from(query: &WebFingerRequest) -> Result<Request, Error>

Performs the conversion.
Source§

impl TryFrom<&Request> for Request<EmptyBody>

Available on crate feature reqwest only.
Source§

type Error = Error

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

fn try_from(query: &WebFingerRequest) -> Result<Request<EmptyBody>, Error>

Performs the conversion.
Source§

impl TryFrom<&Request> for Uri

Source§

type Error = Error

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

fn try_from(query: &WebFingerRequest) -> Result<Uri, Error>

Performs the conversion.
Source§

impl Eq for Request

Source§

impl StructuralPartialEq for Request

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<S, T> FromRequest<S, ViaParts> for T
where S: Send + Sync, T: FromRequestParts<S>,

Source§

type Rejection = <T as FromRequestParts<S>>::Rejection

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>

Perform the extraction.
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, 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<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = Result<U, <U as TryFrom<T>>::Error>> + 'async_trait>>
where T: 'async_trait,

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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