From 30ac33982da169032ec844f357cfc587b5951232 Mon Sep 17 00:00:00 2001 From: mike wakerly Date: Sat, 11 Jul 2020 20:09:21 -0400 Subject: [PATCH] bugfix: Fix AUTO_WEBP handling. Fixes https://github.com/awslabs/serverless-image-handler/pull/195 Fixes https://github.com/awslabs/serverless-image-handler/issues/200 --- CHANGELOG.md | 3 ++- image-request.js | 2 +- test/test-image-request.js | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09c554ff0..9a353e603 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,4 +8,5 @@ * Removed the additional `custom-resource` lambda. * Use `yarn`. * Use `eslint` and `prettier`. -* Add hermetic build using Docker (`make build/serverless-image-handler.zip`) +* Add hermetic build using Docker (`make release`) +* Bugfix: Fixed handling of `AUTO_WEBP` env flag. diff --git a/image-request.js b/image-request.js index 4e54abeab..2a35ba5df 100644 --- a/image-request.js +++ b/image-request.js @@ -313,7 +313,7 @@ class ImageRequest { * @param {Object} event - The request body. */ getOutputFormat(event) { - const autoWebP = process.env.AUTO_WEBP; + const autoWebP = process.env.AUTO_WEBP == "Yes"; if ( autoWebP && event.headers.Accept && diff --git a/test/test-image-request.js b/test/test-image-request.js index 4c290e9c6..09ea20b7f 100644 --- a/test/test-image-request.js +++ b/test/test-image-request.js @@ -754,7 +754,7 @@ describe("getOutputFormat()", () => { it('Should pass if it returns "webp" for an accepts header which includes webp', () => { // Arrange process.env = { - AUTO_WEBP: true, + AUTO_WEBP: "Yes", }; const event = { headers: { @@ -773,7 +773,7 @@ describe("getOutputFormat()", () => { it("Should pass if it returns null for an accepts header which does not include webp", () => { // Arrange process.env = { - AUTO_WEBP: true, + AUTO_WEBP: "Yes", }; const event = { headers: { @@ -792,7 +792,7 @@ describe("getOutputFormat()", () => { it("Should pass if it returns null when AUTO_WEBP is disabled with accepts header including webp", () => { // Arrange process.env = { - AUTO_WEBP: false, + AUTO_WEBP: "No", }; const event = { headers: {