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: StringThe 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?
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
async fn webfinger(request: WebFingerRequest) -> actix_web::Result<WebFingerResponse> {
info!("fetching webfinger resource: {:?}", request);
let subject = request.resource.to_string();
if subject != SUBJECT {
let message = format!("{subject} does not exist");
return Err(actix_web::error::ErrorNotFound(message))?;
}
let rel = Rel::new("http://webfinger.net/rel/profile-page");
let response = if request.rels.is_empty() || request.rels.contains(&rel) {
let link = Link::builder(rel).href(format!("https://example.com/profile/{subject}"));
WebFingerResponse::builder(subject).link(link).build()
} else {
WebFingerResponse::builder(subject).build()
};
Ok(response)
}More examples
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
async fn webfinger(request: WebFingerRequest) -> axum::response::Result<WebFingerResponse> {
info!("fetching webfinger resource: {:?}", request);
let subject = request.resource.to_string();
if subject != SUBJECT {
let message = format!("{subject} does not exist");
return Err((StatusCode::NOT_FOUND, message).into());
}
let rel = Rel::new("http://webfinger.net/rel/profile-page");
let response = if request.rels.is_empty() || request.rels.contains(&rel) {
let link = Link::builder(rel).href(format!("https://example.com/profile/{subject}"));
WebFingerResponse::builder(subject).link(link).build()
} else {
WebFingerResponse::builder(subject).build()
};
Ok(response)
}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.