From 8414db57f00609377336896de20ffdf565d6c924 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Wed, 19 Sep 2018 07:17:19 +0900 Subject: [PATCH] Specify AP Cache-Control (#2735) --- src/server/activitypub.ts | 4 ++++ src/server/activitypub/featured.ts | 1 + src/server/activitypub/followers.ts | 1 + src/server/activitypub/following.ts | 1 + src/server/activitypub/outbox.ts | 2 ++ 5 files changed, 9 insertions(+) diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts index 2cbce8cfb..adbc6639f 100644 --- a/src/server/activitypub.ts +++ b/src/server/activitypub.ts @@ -75,6 +75,7 @@ router.get('/notes/:note', async (ctx, next) => { } ctx.body = pack(await renderNote(note, false)); + ctx.set('Cache-Control', 'public, max-age=180'); setResponseType(ctx); }); @@ -91,6 +92,7 @@ router.get('/notes/:note/activity', async ctx => { } ctx.body = pack(await packActivity(note)); + ctx.set('Cache-Control', 'public, max-age=180'); setResponseType(ctx); }); @@ -122,6 +124,7 @@ router.get('/users/:user/publickey', async ctx => { if (isLocalUser(user)) { ctx.body = pack(renderKey(user)); + ctx.set('Cache-Control', 'public, max-age=180'); setResponseType(ctx); } else { ctx.status = 400; @@ -136,6 +139,7 @@ async function userInfo(ctx: Router.IRouterContext, user: IUser) { } ctx.body = pack(await renderPerson(user as ILocalUser)); + ctx.set('Cache-Control', 'public, max-age=180'); setResponseType(ctx); } diff --git a/src/server/activitypub/featured.ts b/src/server/activitypub/featured.ts index 93c370020..f400cc416 100644 --- a/src/server/activitypub/featured.ts +++ b/src/server/activitypub/featured.ts @@ -34,5 +34,6 @@ export default async (ctx: Router.IRouterContext) => { ); ctx.body = pack(rendered); + ctx.set('Cache-Control', 'private, max-age=0, must-revalidate'); setResponseType(ctx); }; diff --git a/src/server/activitypub/followers.ts b/src/server/activitypub/followers.ts index eb5870344..fcc75fc5b 100644 --- a/src/server/activitypub/followers.ts +++ b/src/server/activitypub/followers.ts @@ -78,6 +78,7 @@ export default async (ctx: Router.IRouterContext) => { // index page const rendered = renderOrderedCollection(partOf, user.followersCount, `${partOf}?page=true`, null); ctx.body = pack(rendered); + ctx.set('Cache-Control', 'private, max-age=0, must-revalidate'); setResponseType(ctx); } }; diff --git a/src/server/activitypub/following.ts b/src/server/activitypub/following.ts index 80878fd4c..2c739ff07 100644 --- a/src/server/activitypub/following.ts +++ b/src/server/activitypub/following.ts @@ -78,6 +78,7 @@ export default async (ctx: Router.IRouterContext) => { // index page const rendered = renderOrderedCollection(partOf, user.followingCount, `${partOf}?page=true`, null); ctx.body = pack(rendered); + ctx.set('Cache-Control', 'private, max-age=0, must-revalidate'); setResponseType(ctx); } }; diff --git a/src/server/activitypub/outbox.ts b/src/server/activitypub/outbox.ts index 1d062f61a..aeb6f25dd 100644 --- a/src/server/activitypub/outbox.ts +++ b/src/server/activitypub/outbox.ts @@ -88,6 +88,7 @@ export default async (ctx: Router.IRouterContext) => { ); ctx.body = pack(rendered); + ctx.set('Cache-Control', 'private, max-age=0, must-revalidate'); setResponseType(ctx); } else { // index page @@ -96,6 +97,7 @@ export default async (ctx: Router.IRouterContext) => { `${partOf}?page=true&since_id=000000000000000000000000` ); ctx.body = pack(rendered); + ctx.set('Cache-Control', 'private, max-age=0, must-revalidate'); setResponseType(ctx); } };