Merge pull request 'Fixes #1051 Fix accept header' (#1058) from activitystreams-content-type into main

Reviewed-on: https://git.joinplu.me/Plume/Plume/pulls/1058
This commit is contained in:
KitaitiMakoto 2022-05-03 17:21:25 +00:00
commit ef57ef91f0
2 changed files with 8 additions and 5 deletions

View File

@ -17,6 +17,7 @@
- Add explanation of sign-up step at sign-up page when email sign-up mode (#1012) - Add explanation of sign-up step at sign-up page when email sign-up mode (#1012)
- Add NOT NULL constraint to email_blocklist table fields (#1016) - Add NOT NULL constraint to email_blocklist table fields (#1016)
- Don't fill empty content when switching rich editor (#1017) - Don't fill empty content when switching rich editor (#1017)
- Fix accept header (#1058)
## [[0.7.1]] - 2022-01-12 ## [[0.7.1]] - 2022-01-12

View File

@ -24,8 +24,8 @@ pub const AP_CONTENT_TYPE: &str =
pub fn ap_accept_header() -> Vec<&'static str> { pub fn ap_accept_header() -> Vec<&'static str> {
vec![ vec![
"application/ld+json; profile=\"https://w3.org/ns/activitystreams\"", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
"application/ld+json;profile=\"https://w3.org/ns/activitystreams\"", "application/ld+json;profile=\"https://www.w3.org/ns/activitystreams\"",
"application/activity+json", "application/activity+json",
"application/ld+json", "application/ld+json",
] ]
@ -87,14 +87,16 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
.map(|header| { .map(|header| {
header header
.split(',') .split(',')
.map(|ct| match ct.trim() { .map(|ct| {
match ct.trim() {
// bool for Forward: true if found a valid Content-Type for Plume first (HTML), false otherwise // bool for Forward: true if found a valid Content-Type for Plume first (HTML), false otherwise
"application/ld+json; profile=\"https://w3.org/ns/activitystreams\"" "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
| "application/ld+json;profile=\"https://w3.org/ns/activitystreams\"" | "application/ld+json;profile=\"https://www.w3.org/ns/activitystreams\""
| "application/activity+json" | "application/activity+json"
| "application/ld+json" => Outcome::Success(ApRequest), | "application/ld+json" => Outcome::Success(ApRequest),
"text/html" => Outcome::Forward(true), "text/html" => Outcome::Forward(true),
_ => Outcome::Forward(false), _ => Outcome::Forward(false),
}
}) })
.fold(Outcome::Forward(false), |out, ct| { .fold(Outcome::Forward(false), |out, ct| {
if out.clone().forwarded().unwrap_or_else(|| out.is_success()) { if out.clone().forwarded().unwrap_or_else(|| out.is_success()) {