Skip to content

Commit ee2ad0d

Browse files
committed
#109 Implement a whitelist for headers as an option to LambdaAPI
1 parent b2a8503 commit ee2ad0d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export declare interface Options {
9494
};
9595
serializer?: SerializerFunction;
9696
version?: string;
97+
errorHeaderWhitelist?: string[];
9798
}
9899

99100
export declare class Request {

index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class API {
2626
this._callbackName = props && props.callback ? props.callback.trim() : 'callback'
2727
this._mimeTypes = props && props.mimeTypes && typeof props.mimeTypes === 'object' ? props.mimeTypes : {}
2828
this._serializer = props && props.serializer && typeof props.serializer === 'function' ? props.serializer : JSON.stringify
29+
this._errorHeaderWhitelist = props && (props.errorHeaderWhitelist || []).map(header => header.toLowerCase())
2930

3031
// Set sampling info
3132
this._sampleCounts = {}
@@ -253,8 +254,17 @@ class API {
253254
// Error messages should never be base64 encoded
254255
response._isBase64 = false
255256

256-
// Strip the headers (TODO: find a better way to handle this)
257-
response._headers = {}
257+
// Strip the headers, keep whitelist
258+
const strippedHeaders = Object.entries(response._headers).reduce((acc, [headerName, value]) => {
259+
if (!this._errorHeaderWhitelist.includes(headerName.toLowerCase())) return acc
260+
261+
return {
262+
...acc,
263+
[headerName]: value
264+
}
265+
}, {})
266+
267+
response._headers = strippedHeaders
258268

259269
let message
260270

0 commit comments

Comments
 (0)