Skip to content

Commit

Permalink
fix: don't set null/undefined HTTP headers
Browse files Browse the repository at this point in the history
Closes #52
  • Loading branch information
theburningmonk committed Jun 21, 2019
1 parent 728c41c commit 14c62ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ describe('HTTP client (correlationIds)', () => {
})
})
})

describe('when there are null or undefined correlation IDs', () => {
it('does not add them to HTTP headers', async () => {
CorrelationIds.replaceAllWith({
awsRequestId: undefined,
awsRegion: null,
'x-correlation-id': 'theburningmonk'
})

await verifyHeaders({}, headers => {
expect(headers['x-correlation-id']).toBe('theburningmonk')
const headerKeys = Object.keys(headers)
expect(headerKeys).not.toContain('awsRequestId')
expect(headerKeys).not.toContain('awsRegion')
})
})
})
})

describe('when the correlationIds option is provided', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/lambda-powertools-http-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function getRequest (uri, method) {
function setHeaders (request, headers) {
const headerNames = Object.keys(headers)
headerNames.forEach(h => {
request = request.set(h, headers[h])
const headerValue = headers[h]
if (headerValue) {
request = request.set(h, headerValue)
}
})

return request
Expand Down

0 comments on commit 14c62ff

Please sign in to comment.