From 5af702a59e38eb700befce6c41e1065742df1ce3 Mon Sep 17 00:00:00 2001 From: William Killerud Date: Thu, 14 Nov 2024 09:59:12 +0100 Subject: [PATCH] fix: set content-type header (#443) * test: add test for content-type header * fix: set content-type header Fixes #442 --- lib/podlet.js | 5 ++--- tests/podlet.test.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/podlet.js b/lib/podlet.js index e63fcab6..1e79ebf8 100644 --- a/lib/podlet.js +++ b/lib/podlet.js @@ -995,9 +995,8 @@ export default class PodiumPodlet { // set "incoming" on res.locals.podium objobj.set('locals.podium', incoming, res); - if (res.header) { - res.header('podlet-version', this.version); - } + res.header('podlet-version', this.version); + res.header('content-type', 'text/html'); res.sendHeaders = () => { res.write(''); diff --git a/tests/podlet.test.js b/tests/podlet.test.js index cfedb393..3b6a37c3 100644 --- a/tests/podlet.test.js +++ b/tests/podlet.test.js @@ -1258,6 +1258,20 @@ tap.test( }, ); +tap.test('res.podiumSend() - should set content-type text/html', async (t) => { + const podlet = new Podlet(DEFAULT_OPTIONS); + const server = new FakeExpressServer(podlet, (req, res) => { + res.podiumSend('

OK!

'); + }); + + await server.listen(); + const result = await server.get({ raw: true }); + + t.equal(result.response, '

OK!

'); + t.equal(result.headers['content-type'], 'text/html; charset=utf-8'); + await server.close(); +}); + // ############################################# // .defaults() // #############################################