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 [WebFingerBuilder] 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 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 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.

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> 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> Same for T

Source§

type Output = T

Should always be Self
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, 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,

Source§

impl<T> MaybeSendSync for T