summaryrefslogtreecommitdiff
path: root/src/server/activitypub.ts
diff options
context:
space:
mode:
authormei23 <m@m544.net>2018-08-21 13:48:03 +0900
committermei23 <m@m544.net>2018-08-21 13:48:03 +0900
commitb42a9e1c4e2191e97ccac0fe115ad7a46421df16 (patch)
tree497dcb66934f13accb5e8385d81e62395105e2c8 /src/server/activitypub.ts
parentRespect visibility in ActivityPub Note/Outbox (diff)
downloadsharkey-b42a9e1c4e2191e97ccac0fe115ad7a46421df16.tar.gz
sharkey-b42a9e1c4e2191e97ccac0fe115ad7a46421df16.tar.bz2
sharkey-b42a9e1c4e2191e97ccac0fe115ad7a46421df16.zip
Set ActivityPub Content-Type
Diffstat (limited to 'src/server/activitypub.ts')
-rw-r--r--src/server/activitypub.ts13
1 files changed, 13 insertions, 0 deletions
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 => {