From: Felix Ableitner Date: Wed, 16 Dec 2020 15:30:44 +0000 (+0100) Subject: Use correct content-type headers for apub inbox (ref #1220) X-Git-Url: http://these/git/%7B%60%24%7BrepoUrl%7D/blob/master/docs/static/%7BrepoUrl%7D?a=commitdiff_plain;h=cbd02f2a8794eb7c3bb3b8a53bdc34fd3fef2586;p=lemmy.git Use correct content-type headers for apub inbox (ref #1220) --- diff --git a/lemmy_apub/src/activity_queue.rs b/lemmy_apub/src/activity_queue.rs index 46780279..4915baea 100644 --- a/lemmy_apub/src/activity_queue.rs +++ b/lemmy_apub/src/activity_queue.rs @@ -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::::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, diff --git a/src/routes/federation.rs b/src/routes/federation.rs index 4d03de77..7ee7e45e 100644 --- a/src/routes/federation.rs +++ b/src/routes/federation.rs @@ -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)), ); } }