mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 15:32:25 -05:00
[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
This commit is contained in:
parent
60d7060895
commit
9d80f7fd68
3 changed files with 57 additions and 6 deletions
|
|
@ -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, "\"", "")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue