From bf8b9bcbad0a4dec550a9d98a27fb62f7b8a38ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Wed, 6 Nov 2019 18:58:24 +0100 Subject: [PATCH] fix setting of Cache-Control for dapp images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- .../controllers/dapps-metadata-controller.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/back-end/controllers/dapps-metadata-controller.js b/back-end/controllers/dapps-metadata-controller.js index fd6032e..8443b54 100644 --- a/back-end/controllers/dapps-metadata-controller.js +++ b/back-end/controllers/dapps-metadata-controller.js @@ -103,17 +103,18 @@ class DAppsMetadataController { try { const dappImage = await DAppImageService.retrieveImage(req.params.hash) - if (dappImage) { - const imageBuffer = Buffer.from(dappImage.content, 'base64') - - res.writeHead(200, { - 'Content-Type': 'image/png', - 'Content-Length': imageBuffer.length, - }) - return void res.end(imageBuffer) + if (!dappImage) { + res.status(404).send() } - res.status(404).send() + const imageBuffer = Buffer.from(dappImage.content, 'base64') + + /* allow for caching of images, since they are the bulk of requests */ + res.set('Cache-Control', 'public, max-age=31557600') + res.set('Content-Type', 'image/png') + res.set('Content-Length', imageBuffer.length) + res.status(200) + return void res.end(imageBuffer) } catch (error) { logger.error(error.message) res.status(404).send()