#[actix_web::get("/.well-known/webfinger")]
pub async fn webfinger(req: HttpRequest, data: web::Data<WebData<'_>>) -> HttpResponse {
let mut resource = None;
for params in req.query_string().split('&') {
if let Some((k, v)) = params.split_once('=') {
if k == "resource" {
resource = Some(v);
}
}
}
let resource = match resource {
Some(r) => r,
None => {
log::warn!("Webfinger not found resource in {}", req.query_string());
return HttpResponse::BadRequest().body("Incorrect query");
}
};
let resource_clean = resource.trim_start_matches("acct:");
let mut parts = resource_clean.splitn(3, '@');
let (user, domain) = match (parts.next(), parts.next(), parts.next()) {
(Some(u), Some(d), None) => (u, d),
_ => {
log::error!("Webfinger incorrect resource {}", resource);
return HttpResponse::NotFound().body("Not found");
}
};
if domain != data.base_domain {
log::error!("Webfinger incorrect resource domain {}", resource);
return HttpResponse::NotFound().body("Not found");
}
log::info!("Webfinger resource user: {}", user);
HttpResponse::NotFound().body("Not found")
}