-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from lowercasename/rk/spec-compliant-ap-headers
Send and accept only spec-compliant ActivityPub headers
- Loading branch information
Showing
6 changed files
with
196 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
import { Request } from "express"; | ||
import { Request, Response } from "express"; | ||
|
||
// From https://www.w3.org/TR/activitypub/#client-to-server-interactions: | ||
// "Servers MAY interpret a Content-Type or Accept header of application/activity+json | ||
// as equivalent to application/ld+json; profile="https://www.w3.org/ns/activitystreams" | ||
// for client-to-server interactions. | ||
// For best compatibility, we always send application/ld+json; profile="https://www.w3.org/ns/activitystreams" | ||
// and accept both application/ld+json; profile="https://www.w3.org/ns/activitystreams" and application/activity+json. | ||
export const activityPubContentType = | ||
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'; | ||
export const alternateActivityPubContentType = "application/activity+json"; | ||
|
||
// Cf. https://www.w3.org/TR/activitypub/#retrieving-objects | ||
export const acceptsActivityPub = (req: Request) => { | ||
return ( | ||
req.headers.accept && | ||
(req.headers.accept.includes("application/activity+json") || | ||
req.headers.accept.includes("application/ld+json")) | ||
const validAcceptHeaders = [ | ||
activityPubContentType, | ||
alternateActivityPubContentType, | ||
]; | ||
return validAcceptHeaders.some( | ||
(header) => req.headers.accept?.includes(header), | ||
); | ||
}; |
Oops, something went wrong.