2 comment::get_apub_comment,
5 get_apub_community_followers,
6 get_apub_community_http,
7 get_apub_community_moderators,
8 get_apub_community_outbox,
11 person::{get_apub_person_http, get_apub_person_outbox, person_inbox},
15 use actix_web::{dev::RequestHead, guard::Guard, http::Method, *};
16 use http_signature_normalization_actix::digest::middleware::VerifyDigest;
17 use lemmy_utils::settings::structs::Settings;
18 use sha2::{Digest, Sha256};
20 pub fn config(cfg: &mut web::ServiceConfig, settings: &Settings) {
21 if settings.federation.enabled {
22 println!("federation enabled, host is {}", settings.hostname);
26 "/c/{community_name}",
27 web::get().to(get_apub_community_http),
30 "/c/{community_name}/followers",
31 web::get().to(get_apub_community_followers),
34 "/c/{community_name}/outbox",
35 web::get().to(get_apub_community_outbox),
38 "/c/{community_name}/moderators",
39 web::get().to(get_apub_community_moderators),
41 .route("/u/{user_name}", web::get().to(get_apub_person_http))
43 "/u/{user_name}/outbox",
44 web::get().to(get_apub_person_outbox),
46 .route("/post/{post_id}", web::get().to(get_apub_post))
47 .route("/comment/{comment_id}", web::get().to(get_apub_comment))
48 .route("/activities/{type_}/{id}", web::get().to(get_activity));
52 .wrap(VerifyDigest::new(Sha256::new()))
53 .guard(InboxRequestGuard)
54 .route("/c/{community_name}/inbox", web::post().to(community_inbox))
55 .route("/u/{user_name}/inbox", web::post().to(person_inbox))
56 .route("/inbox", web::post().to(shared_inbox)),
61 /// Without this, things like webfinger or RSS feeds stop working, as all requests seem to get
62 /// routed into the inbox service (because it covers the root path). So we filter out anything that
63 /// definitely can't be an inbox request (based on Accept header and request method).
64 struct InboxRequestGuard;
66 impl Guard for InboxRequestGuard {
67 fn check(&self, request: &RequestHead) -> bool {
68 if request.method != Method::POST {
71 if let Some(val) = request.headers.get("Content-Type") {
74 .expect("Content-Type header contains non-ascii chars.")
75 .starts_with("application/");