2 comment::get_apub_comment,
5 get_apub_community_featured,
6 get_apub_community_followers,
7 get_apub_community_http,
8 get_apub_community_moderators,
9 get_apub_community_outbox,
12 person::{get_apub_person_http, get_apub_person_outbox, person_inbox},
15 site::{get_apub_site_http, get_apub_site_inbox, get_apub_site_outbox},
18 guard::{Guard, GuardContext},
19 http::{header, Method},
22 use http_signature_normalization_actix::digest::middleware::VerifyDigest;
23 use sha2::{Digest, Sha256};
25 pub fn config(cfg: &mut web::ServiceConfig) {
27 .route("/", web::get().to(get_apub_site_http))
28 .route("/site_outbox", web::get().to(get_apub_site_outbox))
30 "/c/{community_name}",
31 web::get().to(get_apub_community_http),
34 "/c/{community_name}/followers",
35 web::get().to(get_apub_community_followers),
38 "/c/{community_name}/outbox",
39 web::get().to(get_apub_community_outbox),
42 "/c/{community_name}/featured",
43 web::get().to(get_apub_community_featured),
46 "/c/{community_name}/moderators",
47 web::get().to(get_apub_community_moderators),
49 .route("/u/{user_name}", web::get().to(get_apub_person_http))
51 "/u/{user_name}/outbox",
52 web::get().to(get_apub_person_outbox),
54 .route("/post/{post_id}", web::get().to(get_apub_post))
55 .route("/comment/{comment_id}", web::get().to(get_apub_comment))
56 .route("/activities/{type_}/{id}", web::get().to(get_activity));
60 .wrap(VerifyDigest::new(Sha256::new()))
61 .guard(InboxRequestGuard)
62 .route("/c/{community_name}/inbox", web::post().to(community_inbox))
63 .route("/u/{user_name}/inbox", web::post().to(person_inbox))
64 .route("/inbox", web::post().to(shared_inbox))
65 .route("/site_inbox", web::post().to(get_apub_site_inbox)),
69 /// Without this, things like webfinger or RSS feeds stop working, as all requests seem to get
70 /// routed into the inbox service (because it covers the root path). So we filter out anything that
71 /// definitely can't be an inbox request (based on Accept header and request method).
72 struct InboxRequestGuard;
74 impl Guard for InboxRequestGuard {
75 fn check(&self, ctx: &GuardContext) -> bool {
76 if ctx.head().method != Method::POST {
79 if let Some(val) = ctx.head().headers.get(header::CONTENT_TYPE) {
80 return val.as_bytes().starts_with(b"application/");