From 0d1916505f94d4f687058c4b16e459d81acaea92 Mon Sep 17 00:00:00 2001 From: Steffo <41108856+SteffoSpieler@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:09:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20Content-Type=20for=20RSS?= =?UTF-8?q?=20feed=20(#20670)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes https://github.com/TryGhost/Ghost/issues/20634 - this sets the correct Content-Type (`application/rss+xml; charset=utf-8`) for the RSS Endpoint as mentioned in the referenced issue - references for this Content-Type: https://datatracker.ietf.org/doc/id/draft-nottingham-rss-media-type-00 and https://stackoverflow.com/questions/595616/what-is-the-correct-mime-type-to-use-for-an-rss-feed --- ghost/core/core/frontend/services/rss/renderer.js | 2 +- ghost/core/test/e2e-frontend/default_routes.test.js | 10 +++++----- .../mock-express-style/api-vs-frontend.test.js | 6 +++--- .../test/unit/frontend/services/rss/renderer.test.js | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ghost/core/core/frontend/services/rss/renderer.js b/ghost/core/core/frontend/services/rss/renderer.js index 9a15afc918..ab6be75a63 100644 --- a/ghost/core/core/frontend/services/rss/renderer.js +++ b/ghost/core/core/frontend/services/rss/renderer.js @@ -9,7 +9,7 @@ module.exports.render = function render(res, baseUrl, data) { return rssCache .getXML(baseUrl, rssData) .then(function then(feedXml) { - res.set('Content-Type', 'text/xml; charset=UTF-8'); + res.set('Content-Type', 'application/rss+xml; charset=UTF-8'); res.send(feedXml); }); }; diff --git a/ghost/core/test/e2e-frontend/default_routes.test.js b/ghost/core/test/e2e-frontend/default_routes.test.js index 3e03a48b10..7fcc50b8ce 100644 --- a/ghost/core/test/e2e-frontend/default_routes.test.js +++ b/ghost/core/test/e2e-frontend/default_routes.test.js @@ -271,7 +271,7 @@ describe('Default Frontend routing', function () { await request.get('/rss/') .expect(200) .expect('Cache-Control', testUtils.cacheRules.public) - .expect('Content-Type', 'text/xml; charset=utf-8') + .expect('Content-Type', 'application/rss+xml; charset=utf-8') .expect(assertCorrectFrontendHeaders) .expect((res) => { res.text.should.match(//); @@ -283,7 +283,7 @@ describe('Default Frontend routing', function () { await request.get('/author/ghost/rss/') .expect(200) .expect('Cache-Control', testUtils.cacheRules.public) - .expect('Content-Type', 'text/xml; charset=utf-8') + .expect('Content-Type', 'application/rss+xml; charset=utf-8') .expect(assertCorrectFrontendHeaders) .expect((res) => { res.text.should.match(//); @@ -295,7 +295,7 @@ describe('Default Frontend routing', function () { await request.get('/tag/getting-started/rss/') .expect(200) .expect('Cache-Control', testUtils.cacheRules.public) - .expect('Content-Type', 'text/xml; charset=utf-8') + .expect('Content-Type', 'application/rss+xml; charset=utf-8') .expect(assertCorrectFrontendHeaders) .expect((res) => { res.text.should.match(//); @@ -461,7 +461,7 @@ describe('Default Frontend routing', function () { await request.get(`/${settingsCache.get('public_hash')}/rss/`) .expect(200) .expect('Cache-Control', testUtils.cacheRules.private) - .expect('Content-Type', 'text/xml; charset=utf-8') + .expect('Content-Type', 'application/rss+xml; charset=utf-8') .expect(assertCorrectFrontendHeaders) .expect((res) => { res.text.should.match(//); @@ -472,7 +472,7 @@ describe('Default Frontend routing', function () { await request.get(`/tag/getting-started/${settingsCache.get('public_hash')}/rss/`) .expect(200) .expect('Cache-Control', testUtils.cacheRules.private) - .expect('Content-Type', 'text/xml; charset=utf-8') + .expect('Content-Type', 'application/rss+xml; charset=utf-8') .expect(assertCorrectFrontendHeaders) .expect((res) => { res.text.should.match(//); diff --git a/ghost/core/test/regression/mock-express-style/api-vs-frontend.test.js b/ghost/core/test/regression/mock-express-style/api-vs-frontend.test.js index b82ea19546..3090aee06a 100644 --- a/ghost/core/test/regression/mock-express-style/api-vs-frontend.test.js +++ b/ghost/core/test/regression/mock-express-style/api-vs-frontend.test.js @@ -1294,7 +1294,7 @@ describe('Frontend behavior tests', function () { return localUtils.mockExpress.invoke(app, req) .then(function (response) { response.statusCode.should.eql(200); - response.headers['content-type'].should.eql('text/xml; charset=UTF-8'); + response.headers['content-type'].should.eql('application/rss+xml; charset=UTF-8'); }); }); @@ -1448,7 +1448,7 @@ describe('Frontend behavior tests', function () { routes: { '/podcast/rss/': { templates: ['podcast/rss'], - content_type: 'text/xml' + content_type: 'application/rss+xml' }, '/cooking/': { controller: 'channel', @@ -1560,7 +1560,7 @@ describe('Frontend behavior tests', function () { .then(function (response) { response.statusCode.should.eql(200); response.template.should.eql('podcast/rss'); - response.headers['content-type'].should.eql('text/xml; charset=utf-8'); + response.headers['content-type'].should.eql('application/rss+xml'); response.body.match(//g).length.should.eql(2); }); }); diff --git a/ghost/core/test/unit/frontend/services/rss/renderer.test.js b/ghost/core/test/unit/frontend/services/rss/renderer.test.js index 7bf55e1789..2641c7c1c5 100644 --- a/ghost/core/test/unit/frontend/services/rss/renderer.test.js +++ b/ghost/core/test/unit/frontend/services/rss/renderer.test.js @@ -32,7 +32,7 @@ describe('RSS: Renderer', function () { rssCacheStub.firstCall.args.should.eql(['/rss/', {}]); res.set.calledOnce.should.be.true(); - res.set.calledWith('Content-Type', 'text/xml; charset=UTF-8').should.be.true(); + res.set.calledWith('Content-Type', 'application/rss+xml; charset=UTF-8').should.be.true(); res.send.calledOnce.should.be.true(); res.send.calledWith('dummyxml').should.be.true(); @@ -51,7 +51,7 @@ describe('RSS: Renderer', function () { rssCacheStub.firstCall.args.should.eql(['/rss/', {foo: 'bar'}]); res.set.calledOnce.should.be.true(); - res.set.calledWith('Content-Type', 'text/xml; charset=UTF-8').should.be.true(); + res.set.calledWith('Content-Type', 'application/rss+xml; charset=UTF-8').should.be.true(); res.send.calledOnce.should.be.true(); res.send.calledWith('dummyxml').should.be.true(); @@ -71,7 +71,7 @@ describe('RSS: Renderer', function () { rssCacheStub.firstCall.args.should.eql(['/rss/', {foo: 'baz', fizz: 'buzz'}]); res.set.calledOnce.should.be.true(); - res.set.calledWith('Content-Type', 'text/xml; charset=UTF-8').should.be.true(); + res.set.calledWith('Content-Type', 'application/rss+xml; charset=UTF-8').should.be.true(); res.send.calledOnce.should.be.true(); res.send.calledWith('dummyxml').should.be.true();