diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/accept.go | 21 | ||||
-rw-r--r-- | util/util.go | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/util/accept.go b/util/accept.go new file mode 100644 index 0000000..2765c32 --- /dev/null +++ b/util/accept.go @@ -0,0 +1,21 @@ +package util + +import ( + "regexp" + "strings" +) + +// False positive for application/ld+ld, application/activity+ld, application/json+json +var activityRegexp = regexp.MustCompile("application\\/(ld|json|activity)((\\+(ld|json))|$)") + +func AcceptActivity(header string) bool { + accept := false + if strings.Contains(header, ";") { + split := strings.Split(header, ";") + accept = accept || activityRegexp.MatchString(split[0]) + accept = accept || strings.Contains(split[len(split)-1], "profile=\"https://www.w3.org/ns/activitystreams\"") + } else { + accept = accept || activityRegexp.MatchString(header) + } + return accept +} diff --git a/util/util.go b/util/util.go index a56e871..1feb53a 100644 --- a/util/util.go +++ b/util/util.go @@ -29,7 +29,7 @@ func GetActorInstance(path string) (string, string) { } } - re = regexp.MustCompile(`(https?://)(www)?([\w\d-_.:]+)(/|\s+|\r|\r\n)?$`) + re = regexp.MustCompile(`(https?://)?(www)?([\w\d-_.:]+)(/|\s+|\r|\r\n)?$`) mainActor := re.MatchString(path) if mainActor { match := re.FindStringSubmatch(path) |