From de08d0c95942517a86aeaa860437da1498c0e353 Mon Sep 17 00:00:00 2001 From: Sean Harkins Date: Fri, 14 Jun 2019 17:56:54 -0400 Subject: [PATCH 1/4] Include missing through2 dependency. --- packages/api-lib/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/api-lib/package.json b/packages/api-lib/package.json index 93ce789..3fad49e 100644 --- a/packages/api-lib/package.json +++ b/packages/api-lib/package.json @@ -36,6 +36,7 @@ "pump": "^3.0.0", "request": "^2.88.0", "request-promise-native": "^1.0.5", + "through2": "^3.0.1", "uuid": "^3.3.2", "winston": "^2.2.0" }, From 1566bf263bfa0c9f4a48b730177c6b09cfe52a02 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Mon, 17 Jun 2019 17:23:40 -0400 Subject: [PATCH 2/4] update CHANGELOG --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b3e40c..099a940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [v0.2.5] - 2019-06-17 + +### Fixed +- Added missing dependency (through2) + +### Removed +- Removed gzip compression which caused problems with APIGateway. Use APIGateway to enable compression instead rather than in the library. + ## [v0.2.4] - 2019-06-02 ### Added @@ -97,6 +105,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Refactor and improve splitting [Unreleased]: https://github.com/sat-utils/sat-api/compare/master...develop +[v0.2.5]: https://github.com/sat-utils/sat-api/compare/v0.2.4...v0.2.5 [v0.2.4]: https://github.com/sat-utils/sat-api/compare/v0.2.3...v0.2.4 [v0.2.3]: https://github.com/sat-utils/sat-api/compare/v0.2.2...v0.2.3 [v0.2.2]: https://github.com/sat-utils/sat-api/compare/v0.2.1...v0.2.2 From 9b8f8c14519ca1887cdfbe5612273f589de7c2dd Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Mon, 17 Jun 2019 17:28:13 -0400 Subject: [PATCH 3/4] remove gzip compression on response --- packages/api/index.js | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/packages/api/index.js b/packages/api/index.js index 4e46b16..59dc7c0 100644 --- a/packages/api/index.js +++ b/packages/api/index.js @@ -2,10 +2,7 @@ 'use strict' -const zlib = require('zlib') -const { promisify } = require('util') const satlib = require('@sat-utils/api-lib') -const gzip = promisify(zlib.gzip) module.exports.handler = async (event) => { // determine endpoint @@ -21,32 +18,15 @@ module.exports.handler = async (event) => { } } - const lowerCaseHeaders = (headers) => Object.entries(headers).reduce( - (acc, [key, value]) => { - acc[typeof key === 'string' ? key.toLowerCase() : key] = value - return acc - }, {} - ) - const buildResponse = async (statusCode, result) => { - const headers = lowerCaseHeaders(event.headers) - const acceptEncoding = headers['accept-encoding'] || '' - const encodings = acceptEncoding.split(',') - const isGzip = encodings.includes('gzip') const response = { statusCode, headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', // Required for CORS support to work 'Access-Control-Allow-Credentials': true - } - } - if (isGzip) { - const zipped = await gzip(result) - response.body = zipped.toString('base64') - response.headers['Content-Encoding'] = 'gzip' - } else { - response.body = result + }, + body: result } return response } From c911b22a42f9040f881c8e048f50430cc2748f77 Mon Sep 17 00:00:00 2001 From: Sean Harkins Date: Tue, 18 Jun 2019 09:37:32 -0400 Subject: [PATCH 4/4] Fix failing gzip test. --- packages/api/tests/test_handler.js | 57 ------------------------------ 1 file changed, 57 deletions(-) diff --git a/packages/api/tests/test_handler.js b/packages/api/tests/test_handler.js index bd77d5a..7c0bd5b 100644 --- a/packages/api/tests/test_handler.js +++ b/packages/api/tests/test_handler.js @@ -2,9 +2,6 @@ const test = require('ava') const sinon = require('sinon') const proxyquire = require('proxyquire') const createEvent = require('aws-event-mocks') -const zlib = require('zlib') -const { promisify } = require('util') -const gunzip = promisify(zlib.gunzip) test('handler calls search with parameters', async (t) => { const result = { value: 'value' } @@ -84,57 +81,3 @@ test('handler returns 404 for error', async (t) => { t.is(actual.statusCode, 404) t.is(actual.body, errorMessage) }) - -test('handler gzips response', async (t) => { - const result = { value: 'value' } - const search = sinon.stub().resolves(result) - const satlib = { - api: { - search - } - } - const lambda = proxyquire('../index.js', { - '@sat-utils/api-lib': satlib - }) - const host = 'host' - const httpMethod = 'GET' - const path = 'path' - - let event = createEvent({ - template: 'aws:apiGateway', - merge: { - headers: { - Host: host, - 'accept-encoding': 'gzip, deflate' - }, - requestContext: {}, - httpMethod, - path - } - }) - - let actual = await lambda.handler(event) - t.is(actual.statusCode, 200) - let unzippedBody = await gunzip(Buffer.from(actual.body, 'base64')) - t.is(unzippedBody.toString(), JSON.stringify(result)) - t.is(actual.headers['Content-Encoding'], 'gzip') - - event = createEvent({ - template: 'aws:apiGateway', - merge: { - headers: { - Host: host, - 'Accept-Encoding': 'gzip, deflate' - }, - requestContext: {}, - httpMethod, - path - } - }) - - actual = await lambda.handler(event) - t.is(actual.statusCode, 200) - unzippedBody = await gunzip(Buffer.from(actual.body, 'base64')) - t.is(unzippedBody.toString(), JSON.stringify(result), - 'Ignores header case sensitivity') -})