Skip to content

Commit

Permalink
return a Vary: Accept header for all dual-format endpoints #365 (#1…
Browse files Browse the repository at this point in the history
…3044)

`/users/:user`, `/@:user`, `/notes/:note` return different responses
depending on the request's `Accept:` header. If we don't consistently
return a `Vary: Accept` header, browsers and caching proxies will get
confused, and return AP representations when HTML was requested, or
vice versa.

Co-authored-by: dakkar <[email protected]>
Co-authored-by: syuilo <[email protected]>
  • Loading branch information
3 people authored Jan 21, 2024
1 parent 4c87e98 commit fb309f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/backend/src/server/ActivityPubServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ export class ActivityPubServerService {
});

fastify.get<{ Params: { user: string; } }>('/users/:user', { constraints: { apOrHtml: 'ap' } }, async (request, reply) => {
vary(reply.raw, 'Accept');

const userId = request.params.user;

const user = await this.usersRepository.findOneBy({
Expand All @@ -660,6 +662,8 @@ export class ActivityPubServerService {
});

fastify.get<{ Params: { user: string; } }>('/@:user', { constraints: { apOrHtml: 'ap' } }, async (request, reply) => {
vary(reply.raw, 'Accept');

const user = await this.usersRepository.findOneBy({
usernameLower: request.params.user.toLowerCase(),
host: IsNull(),
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/server/web/ClientServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ export class ClientServerService {
isSuspended: false,
});

vary(reply.raw, 'Accept');

if (user != null) {
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
const meta = await this.metaService.fetch();
Expand Down Expand Up @@ -515,6 +517,8 @@ export class ClientServerService {
return;
}

vary(reply.raw, 'Accept');

reply.redirect(`/@${user.username}${ user.host == null ? '' : '@' + user.host}`);
});

Expand Down

0 comments on commit fb309f3

Please sign in to comment.