Use correct content-type headers for apub inbox (ref #1220)
authorFelix Ableitner <me@nutomic.com>
Wed, 16 Dec 2020 15:30:44 +0000 (16:30 +0100)
committerFelix Ableitner <me@nutomic.com>
Wed, 16 Dec 2020 15:30:44 +0000 (16:30 +0100)
lemmy_apub/src/activity_queue.rs
src/routes/federation.rs

index 467802794f606f4c16b600257fead7a7e92f9fec..4915baea73bd80f8786d71bc5578e609ba64197b 100644 (file)
@@ -3,6 +3,7 @@ use crate::{
   extensions::signatures::sign_and_send,
   insert_activity,
   ActorType,
+  APUB_JSON_CONTENT_TYPE,
 };
 use activitystreams::{
   base::{BaseExt, Extends, ExtendsExt},
@@ -261,7 +262,7 @@ impl ActixJob for SendActivityTask {
   fn run(self, state: Self::State) -> Self::Future {
     Box::pin(async move {
       let mut headers = BTreeMap::<String, String>::new();
-      headers.insert("Content-Type".into(), "application/json".into());
+      headers.insert("Content-Type".into(), APUB_JSON_CONTENT_TYPE.to_string());
       let result = sign_and_send(
         &state.client,
         headers,
index 4d03de770231b3100c79fa2a7a54f6b1210cd716..7ee7e45e483083e66a9ddc1f18db508b83f8b8fb 100644 (file)
@@ -22,13 +22,18 @@ pub fn config(cfg: &mut web::ServiceConfig) {
     println!("federation enabled, host is {}", Settings::get().hostname);
     let digest_verifier = VerifyDigest::new(Sha256::new());
 
-    let header_guard = guard::Any(guard::Header("Accept", APUB_JSON_CONTENT_TYPE))
+    let header_guard_accept = guard::Any(guard::Header("Accept", APUB_JSON_CONTENT_TYPE))
       .or(guard::Header("Accept", APUB_JSON_CONTENT_TYPE_LONG));
+    let header_guard_content_type =
+      guard::Any(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE))
+        .or(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE_LONG))
+        // TODO: compatibility with previous lemmy versions, remove this later
+        .or(guard::Header("Content-Type", "application/json"));
 
     cfg
       .service(
         web::scope("/")
-          .guard(header_guard)
+          .guard(header_guard_accept)
           .route(
             "/c/{community_name}",
             web::get().to(get_apub_community_http),
@@ -49,19 +54,12 @@ pub fn config(cfg: &mut web::ServiceConfig) {
       )
       // Inboxes dont work with the header guard for some reason.
       .service(
-        web::resource("/c/{community_name}/inbox")
-          .wrap(digest_verifier.clone())
-          .route(web::post().to(community_inbox)),
-      )
-      .service(
-        web::resource("/u/{user_name}/inbox")
-          .wrap(digest_verifier.clone())
-          .route(web::post().to(user_inbox)),
-      )
-      .service(
-        web::resource("/inbox")
+        web::scope("/")
           .wrap(digest_verifier)
-          .route(web::post().to(shared_inbox)),
+          .guard(header_guard_content_type)
+          .route("/c/{community_name}/inbox", web::post().to(community_inbox))
+          .route("/u/{user_name}/inbox", web::post().to(user_inbox))
+          .route("/inbox", web::post().to(shared_inbox)),
       );
   }
 }