diff --git a/server/federation/index.js b/server/federation/index.js index 1d9e45aa..03969a44 100644 --- a/server/federation/index.js +++ b/server/federation/index.js @@ -32,7 +32,7 @@ router.get('/m/:event_id:json(.json)?', async (req, res) => { const event_id = req.params.event_id const json = req.params.json const acceptHtml = req.accepts('html', 'application/json', 'application/activity+json', 'application/ld+json') === 'html' - if (acceptHtml && !json) { return res.redirect(301, `/event/${event_id}`) } + if (acceptHtml && !json) { return res.redirect(302, `/event/${event_id}`) } const event = await Event.findByPk(req.params.event_id, { include: [User, Tag, Place] }) if (!event) { return res.status(404).send('Not found') } const eventAp = event.toAP(settingsController.settings) diff --git a/server/federation/users.js b/server/federation/users.js index 74fd9838..f9b3f48b 100644 --- a/server/federation/users.js +++ b/server/federation/users.js @@ -10,9 +10,9 @@ const get = require('lodash/get') module.exports = { get (req, res) { - if (req.accepts(['json','html']) !== 'json') { + if (req.accepts('application/activity+json', 'application/ld+json', 'application/json', 'html') === 'html'){ log.debug('[FEDI] Get actor but prefer text/html, redirect to homepage') - return res.redirect(301, '/') + return res.redirect(302, '/') } log.debug('[FEDI] Get actor') const settings = settingsController.settings diff --git a/tests/ap.test.js b/tests/ap.test.js index 8459fccf..83414b4e 100644 --- a/tests/ap.test.js +++ b/tests/ap.test.js @@ -1,5 +1,4 @@ const request = require('supertest') -const dayjs = require('dayjs') const path = require('path') const admin = { username: 'admin', password: 'test', grant_type: 'password', client_id: 'self' } @@ -94,6 +93,28 @@ describe('Webfinger', () => { }) describe('AP', () => { + + test('should redirect to / on html as accepted content type', async () => { + await request(app).get('/federation/u/relay') + .set('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8') + .expect(302) + .expect('Location', '/') + }) + + test('should return a json when ld+json is accepted', async () => { + await request(app).get('/federation/u/relay') + .set('Accept', 'application/ld+json') + .expect(200) + .expect('Content-Type', /json/) + }) + + test('should return a json when activity+json is accepted', async () => { + await request(app).get('/federation/u/relay') + .set('Accept', 'application/activity+json') + .expect(200) + .expect('Content-Type', /json/) + }) + test('should return the AP Actor', async () => { const response = await request(app).get('/federation/u/relay') .expect(200)