Struct WebFingerResponse

Source
pub struct WebFingerResponse {
    pub subject: String,
    pub aliases: Option<Vec<String>>,
    pub properties: Option<HashMap<String, String>>,
    pub links: Vec<Link>,
}
Expand description

A WebFinger response.

This represents the response portion of a WebFinger query that is returned by a WebFinger server.

See RFC 7033 Section 4.4 for more information.

§Examples

use webfinger_rs::{Link, WebFingerResponse};

let avatar = Link::builder("http://webfinger.net/rel/avatar")
    .href("https://example.com/avatar.png")
    .build();
let profile = Link::builder("http://webfinger.net/rel/profile-page")
    .href("https://example.com/profile/carol")
    .build();
let response = WebFingerResponse::builder("acct:carol@example.com")
    .alias("https://example.com/profile/carol")
    .property("https://example.com/ns/role", "developer")
    .link(avatar)
    .link(profile)
    .build();

Response can be used as a response in Axum handlers as it implements axum::response::IntoResponse.

use axum::response::IntoResponse;
use webfinger_rs::{Link, WebFingerRequest, WebFingerResponse};

async fn handler(request: WebFingerRequest) -> WebFingerResponse {
    // ... handle the request ...
    WebFingerResponse::builder("acct:carol@example.com")
        .alias("https://example.com/profile/carol")
        .property("https://example.com/ns/role", "developer")
        .link(
            Link::builder("http://webfinger.net/rel/avatar")
                .href("https://example.com/avatar.png"),
        )
        .build()
}

Fields§

§subject: String

The subject of the response.

This is the URI of the resource that the response is about.

Defined in RFC 7033 Section 4.4.1

§aliases: Option<Vec<String>>

The aliases of the response.

Defined in RFC 7033 Section 4.4.2

§properties: Option<HashMap<String, String>>

The properties of the response.

Defined in RFC 7033 Section 4.4.3

§links: Vec<Link>

The links of the response.

Defined in RFC 7033 Section 4.4.4

Implementations§

Source§

impl WebFingerResponse

Source

pub async fn try_from_reqwest( response: Response, ) -> Result<WebFingerResponse, Error>

Available on crate feature reqwest only.

Converts a reqwest response into a WebFinger response.

Source§

impl Response

Source

pub fn new<S: Into<String>>(subject: S) -> Self

Create a new response with the given subject.

Source

pub fn builder<S: Into<String>>(subject: S) -> Builder

Create a new Builder with the given subject.

§Examples
use webfinger_rs::{Link, WebFingerResponse};

let avatar =
    Link::builder("http://webfinger.net/rel/avatar").href("https://example.com/avatar.png");
let response = WebFingerResponse::builder("acct:carol@example.com")
    .alias("https://example.com/profile/carol")
    .property("https://example.com/ns/role", "developer")
    .link(avatar)
    .build();
Examples found in repository?
examples/actix.rs (line 57)
47async fn webfinger(request: WebFingerRequest) -> actix_web::Result<WebFingerResponse> {
48    info!("fetching webfinger resource: {:?}", request);
49    let subject = request.resource.to_string();
50    if subject != SUBJECT {
51        let message = format!("{subject} does not exist");
52        return Err(actix_web::error::ErrorNotFound(message))?;
53    }
54    let rel = Rel::new("http://webfinger.net/rel/profile-page");
55    let response = if request.rels.is_empty() || request.rels.contains(&rel) {
56        let link = Link::builder(rel).href(format!("https://example.com/profile/{subject}"));
57        WebFingerResponse::builder(subject).link(link).build()
58    } else {
59        WebFingerResponse::builder(subject).build()
60    };
61    Ok(response)
62}
More examples
Hide additional examples
examples/axum.rs (line 57)
47async fn webfinger(request: WebFingerRequest) -> axum::response::Result<WebFingerResponse> {
48    info!("fetching webfinger resource: {:?}", request);
49    let subject = request.resource.to_string();
50    if subject != SUBJECT {
51        let message = format!("{subject} does not exist");
52        return Err((StatusCode::NOT_FOUND, message).into());
53    }
54    let rel = Rel::new("http://webfinger.net/rel/profile-page");
55    let response = if request.rels.is_empty() || request.rels.contains(&rel) {
56        let link = Link::builder(rel).href(format!("https://example.com/profile/{subject}"));
57        WebFingerResponse::builder(subject).link(link).build()
58    } else {
59        WebFingerResponse::builder(subject).build()
60    };
61    Ok(response)
62}

Trait Implementations§

Source§

impl Clone for Response

Source§

fn clone(&self) -> Response

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 Response

Custom debug implementation to avoid printing None fields

Source§

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

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

impl<'de> Deserialize<'de> for Response

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 Display for Response

Source§

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

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

impl IntoResponse for WebFingerResponse

Available on crate feature axum only.
Source§

fn into_response(self) -> AxumResponse

Converts a WebFinger response into an axum response.

This is used to convert a WebFingerResponse into an axum response in an axum route handler. The response will be serialized as JSON and the Content-Type header will be set to application/jrd+json.

See the axum example for more information.

§Example
use axum::response::IntoResponse;
use webfinger_rs::{Link, WebFingerRequest, WebFingerResponse};

async fn handler(request: WebFingerRequest) -> impl IntoResponse {
    // ... your code to handle the webfinger request ...
    let subject = request.resource.to_string();
    let link = Link::builder("http://webfinger.net/rel/profile-page")
        .href(format!("https://example.com/profile/{subject}"));
    WebFingerResponse::builder(subject).link(link).build()
}
Source§

impl PartialEq for Response

Source§

fn eq(&self, other: &Response) -> 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 Responder for WebFingerResponse

Available on crate feature actix only.
Source§

type Body = <Json<Response> as Responder>::Body

Source§

fn respond_to(self, _request: &HttpRequest) -> HttpResponse<Self::Body>

Convert self to HttpResponse.
Source§

fn customize(self) -> CustomizeResponder<Self>
where Self: Sized,

Wraps responder to allow alteration of its response. Read more
Source§

impl Serialize for Response

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<&Response> for Response<()>

Source§

type Error = Error

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

fn try_from(_: &WebFingerResponse) -> Result<Response<()>, Error>

Performs the conversion.
Source§

impl TryFrom<Response> for WebFingerResponse

Available on crate feature reqwest only.
Source§

type Error = Error

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

fn try_from<'async_trait>( response: Response, ) -> Pin<Box<dyn Future<Output = Result<WebFingerResponse, Error>> + Send + 'async_trait>>

Performs the conversion.
Source§

impl Eq for Response

Source§

impl StructuralPartialEq for Response

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<T, S> Handler<IntoResponseHandler, S> for T
where T: IntoResponse + Clone + Send + Sync + 'static,

Source§

type Future = Ready<Response<Body>>

The type of future calling this handler returns.
Source§

fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future

Call the handler with the given request.
Source§

fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>
where L: Layer<HandlerService<Self, T, S>> + Clone, <L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,

Apply a tower::Layer to the handler. Read more
Source§

fn with_state(self, state: S) -> HandlerService<Self, T, S>

Convert the handler into a Service by providing the state
Source§

impl<H, T> HandlerWithoutStateExt<T> for H
where H: Handler<T, ()>,

Source§

fn into_service(self) -> HandlerService<H, T, ()>

Convert the handler into a Service and no state.
Source§

fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>

Convert the handler into a MakeService and no state. Read more
Source§

fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>

Convert the handler into a MakeService which stores information about the incoming connection and has no state. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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,