fix: update proceedOnActivityPub middleware to handle how Mastodon doesn't send the 'Accepts' header

This commit is contained in:
Julian Lam
2023-12-21 15:49:51 -05:00
parent 885278842b
commit dd480aa4f6
2 changed files with 5 additions and 5 deletions

View File

@@ -101,7 +101,7 @@ Controller.getInbox = async (req, res) => {
};
Controller.postInbox = async (req, res) => {
// Note: internal-only, hence no exposure via src/api
// Note: underlying methods are internal use only, hence no exposure via src/api
switch (req.body.type) {
case 'Follow': {
await activitypub.inbox.follow(req.body.actor.name, req.body.object.name);

View File

@@ -310,8 +310,8 @@ middleware.handleMultipart = (req, res, next) => {
middleware.proceedOnActivityPub = (req, res, next) => {
// For whatever reason, express accepts does not recognize "profile" as a valid differentiator
// Therefore, manual header parsing is used here.
const { accept } = req.headers;
if (!accept || !meta.config.activitypubEnabled) {
const { accept, 'content-type': contentType } = req.headers;
if (!meta.config.activitypubEnabled || !(accept && contentType)) {
return next('route');
}
@@ -319,10 +319,10 @@ middleware.proceedOnActivityPub = (req, res, next) => {
'application/activity+json',
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
];
const pass = accept.split(',').some((value) => {
const pass = (accept && accept.split(',').some((value) => {
const parts = value.split(';').map(v => v.trim());
return acceptable.includes(value || parts[0]);
});
})) || (contentType && acceptable.includes(contentType));
if (!pass) {
return next('route');