Skip to content

Commit

Permalink
Merge pull request #1185 from ScoobySmack2612/HTN/handle-canonical-sa…
Browse files Browse the repository at this point in the history
…nitized-headers

Pkg: httpHeaderNormalizer to handle canonical sanitized headers
  • Loading branch information
willfarrell authored Mar 2, 2024
2 parents 53c2227 + f5451a6 commit e886e2d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions packages/http-header-normalizer/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,26 @@ test('It should not fail if the event does not contain headers', async (t) => {
t.deepEqual(resultingEvent, expectedEvent)
t.deepEqual(resultingEvent.rawHeaders, undefined)
})

test('It should not fail given a corrupted header key', async (t) => {
const handler = middy((event, context) => event)

handler.use(httpHeaderNormalizer({ canonical: true }))

const event = {
headers: {
'X----': 'foo'
}
}

const expectedHeaders = {
'X----': 'foo'
}

const originalHeaders = { ...event.headers }

const resultingEvent = await handler(event, context)

t.deepEqual(resultingEvent.headers, expectedHeaders)
t.deepEqual(resultingEvent.rawHeaders, originalHeaders)
})
2 changes: 1 addition & 1 deletion packages/http-header-normalizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const normalizeHeaderKey = (key, canonical) => {

return lowerCaseKey
.split('-')
.map((text) => text[0].toUpperCase() + text.substr(1))
.map((text) => (text[0] || '').toUpperCase() + text.substr(1))
.join('-')
}

Expand Down

0 comments on commit e886e2d

Please sign in to comment.