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
impl WebFingerResponse
Sourcepub async fn try_from_reqwest(
response: Response,
) -> Result<WebFingerResponse, Error>
Available on crate feature reqwest
only.
pub async fn try_from_reqwest( response: Response, ) -> Result<WebFingerResponse, Error>
reqwest
only.Converts a reqwest response into a WebFinger response.
Source§impl Response
impl Response
Sourcepub fn builder<S: Into<String>>(subject: S) -> Builder
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?
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
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<'de> Deserialize<'de> for Response
impl<'de> Deserialize<'de> for Response
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl IntoResponse for WebFingerResponse
Available on crate feature axum
only.
impl IntoResponse for WebFingerResponse
axum
only.Source§fn into_response(self) -> AxumResponse
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.
impl Responder for WebFingerResponse
actix
only.type Body = <Json<Response> as Responder>::Body
Source§fn respond_to(self, _request: &HttpRequest) -> HttpResponse<Self::Body>
fn respond_to(self, _request: &HttpRequest) -> HttpResponse<Self::Body>
HttpResponse
.Source§impl TryFrom<Response> for WebFingerResponse
Available on crate feature reqwest
only.
impl TryFrom<Response> for WebFingerResponse
reqwest
only.impl Eq for Response
impl StructuralPartialEq for Response
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
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>>,
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>>,
tower::Layer
to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Service
by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Service
and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
MakeService
and no state. Read moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
MakeService
which stores information
about the incoming connection and has no state. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.