diff options
author | 2024-01-22 15:33:01 +0100 | |
---|---|---|
committer | 2024-01-22 14:33:01 +0000 | |
commit | 9d80f7fd68c5a1c243f1d90a05d8fec028f1c9e8 (patch) | |
tree | 4a17c7a92801bc06f6ea09f5b8fca0926cf2ba3d /internal/federation/federatingactor.go | |
parent | [docs] use latest cavage link for http signatures (#2565) (diff) | |
download | gotosocial-9d80f7fd68c5a1c243f1d90a05d8fec028f1c9e8.tar.xz |
[feature] Allow "charset=utf8" in incoming AP POST requests (#2564)
* [feature] Allow "charset=utf8" in incoming AP POST requests
* changed my mind
* document POSTing to a GtS inbox
* correct link
Diffstat (limited to 'internal/federation/federatingactor.go')
-rw-r--r-- | internal/federation/federatingactor.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/internal/federation/federatingactor.go b/internal/federation/federatingactor.go index 8fc47462d..b91165bb1 100644 --- a/internal/federation/federatingactor.go +++ b/internal/federation/federatingactor.go @@ -40,7 +40,7 @@ import ( // - application/activity+json // - application/ld+json;profile=https://w3.org/ns/activitystreams // -// Where for the above we are leniant with whitespace and quotes. +// Where for the above we are leniant with whitespace, quotes, and charset. func IsASMediaType(ct string) bool { var ( // First content-type part, @@ -48,7 +48,8 @@ func IsASMediaType(ct string) bool { p1 string = ct //nolint:revive // Second content-type part, - // contains AS IRI if provided + // contains AS IRI or charset + // if provided. p2 string ) @@ -56,7 +57,11 @@ func IsASMediaType(ct string) bool { sep := strings.IndexByte(ct, ';') if sep >= 0 { p1 = ct[:sep] + + // Trim all start/end + // space of second part. p2 = ct[sep+1:] + p2 = strings.Trim(p2, " ") } // Trim any ending space from the @@ -65,12 +70,12 @@ func IsASMediaType(ct string) bool { switch p1 { case "application/activity+json": - return p2 == "" + // Accept with or without charset. + // This should be case insensitive. + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type#charset + return p2 == "" || strings.EqualFold(p2, "charset=utf-8") case "application/ld+json": - // Trim all start/end space. - p2 = strings.Trim(p2, " ") - // Drop any quotes around the URI str. p2 = strings.ReplaceAll(p2, "\"", "") |