mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-15 08:54:01 +00:00
Merge pull request 'Use correct content-type headers for apub inbox (ref #1220)' (#150) from inbox-headers into main
Reviewed-on: https://yerbamate.ml/LemmyNet/lemmy/pulls/150
This commit is contained in:
commit
5b2fb07e44
2 changed files with 14 additions and 15 deletions
|
@ -3,6 +3,7 @@ use crate::{
|
||||||
extensions::signatures::sign_and_send,
|
extensions::signatures::sign_and_send,
|
||||||
insert_activity,
|
insert_activity,
|
||||||
ActorType,
|
ActorType,
|
||||||
|
APUB_JSON_CONTENT_TYPE,
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
base::{BaseExt, Extends, ExtendsExt},
|
base::{BaseExt, Extends, ExtendsExt},
|
||||||
|
@ -261,7 +262,7 @@ impl ActixJob for SendActivityTask {
|
||||||
fn run(self, state: Self::State) -> Self::Future {
|
fn run(self, state: Self::State) -> Self::Future {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let mut headers = BTreeMap::<String, String>::new();
|
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(
|
let result = sign_and_send(
|
||||||
&state.client,
|
&state.client,
|
||||||
headers,
|
headers,
|
||||||
|
|
|
@ -22,13 +22,18 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
println!("federation enabled, host is {}", Settings::get().hostname);
|
println!("federation enabled, host is {}", Settings::get().hostname);
|
||||||
let digest_verifier = VerifyDigest::new(Sha256::new());
|
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));
|
.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
|
cfg
|
||||||
.service(
|
.service(
|
||||||
web::scope("/")
|
web::scope("/")
|
||||||
.guard(header_guard)
|
.guard(header_guard_accept)
|
||||||
.route(
|
.route(
|
||||||
"/c/{community_name}",
|
"/c/{community_name}",
|
||||||
web::get().to(get_apub_community_http),
|
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.
|
// Inboxes dont work with the header guard for some reason.
|
||||||
.service(
|
.service(
|
||||||
web::resource("/c/{community_name}/inbox")
|
web::scope("/")
|
||||||
.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")
|
|
||||||
.wrap(digest_verifier)
|
.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)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue