Skip to content

Commit

Permalink
Translate response headers
Browse files Browse the repository at this point in the history
  • Loading branch information
posquit0 committed May 4, 2018
1 parent 2bceb17 commit acb79b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/utils.js
@@ -0,0 +1,15 @@
'use strict';


/**
* Convert Map to an Object so it can be converted to JSON.
*
* @param {Map} map - Map object to convert.
* @return {Object} Converted object.
*/
module.exports.convertMapToObject = map => {
const obj = {};
for (const [key, val] of map.entries())
obj[key] = val;
return obj;
};
4 changes: 3 additions & 1 deletion translators/aws-proxy-translator.js
@@ -1,5 +1,7 @@
'use strict';

const { convertMapToObject } = require('../lib/utils');


/**
* Return middleware that translates the request and response from/to
Expand All @@ -15,7 +17,6 @@ function AwsProxyTranslator(options = {}) {
} = options;

// TODO: translate the request
// TODO: translate the response headers
return async (ctx, next) => {
ctx.headers = new Map();

Expand All @@ -24,6 +25,7 @@ function AwsProxyTranslator(options = {}) {
const response = {
isBase64Encoded,
statusCode: ctx.status || 500,
headers: convertMapToObject(ctx.headers),
body: JSON.stringify(ctx.body)
};
return response;
Expand Down

0 comments on commit acb79b7

Please sign in to comment.