From b42a9e1c4e2191e97ccac0fe115ad7a46421df16 Mon Sep 17 00:00:00 2001 From: mei23 Date: Tue, 21 Aug 2018 13:48:03 +0900 Subject: Set ActivityPub Content-Type --- src/server/activitypub.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/server/activitypub.ts') diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts index 26eaa68fe8..d04ffd38f9 100644 --- a/src/server/activitypub.ts +++ b/src/server/activitypub.ts @@ -41,10 +41,20 @@ function inbox(ctx: Router.IRouterContext) { } function isActivityPubReq(ctx: Router.IRouterContext) { + ctx.response.vary('Accept'); const accepted = ctx.accepts('html', 'application/activity+json', 'application/ld+json'); return ['application/activity+json', 'application/ld+json'].includes(accepted as string); } +export function setResponseType(ctx: Router.IRouterContext) { + const accpet = ctx.accepts('application/activity+json', 'application/ld+json'); + if (accpet === 'application/ld+json') { + ctx.response.type = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"; charset=utf-8'; + } else { + ctx.response.type = 'application/activity+json; charset=utf-8'; + } +} + // inbox router.post('/inbox', json(), inbox); router.post('/users/:user/inbox', json(), inbox); @@ -64,6 +74,7 @@ router.get('/notes/:note', async (ctx, next) => { } ctx.body = pack(await renderNote(note, false)); + setResponseType(ctx); }); // outbox @@ -91,6 +102,7 @@ router.get('/users/:user/publickey', async ctx => { if (isLocalUser(user)) { ctx.body = pack(renderKey(user)); + setResponseType(ctx); } else { ctx.status = 400; } @@ -104,6 +116,7 @@ async function userInfo(ctx: Router.IRouterContext, user: IUser) { } ctx.body = pack(await renderPerson(user as ILocalUser)); + setResponseType(ctx); } router.get('/users/:user', async ctx => { -- cgit v1.2.3-freya