Skip to content

Commit

Permalink
fix: perf
Browse files Browse the repository at this point in the history
  • Loading branch information
willfarrell committed Dec 10, 2023
1 parent c52b834 commit fa6c1ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/http-content-negotiation/__benchmarks__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ const warmHandler = setupHandler()

await bench
.add(
'Parse Headers',
'Parse headers',
async (
event = {
headers: {
'Accept-Charset': 'utf-8, iso-8859-5, unicode-1-1;q=0.8',
'Accept-Encoding': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'da, en-gb;q=0.8, en;q=0.7',
Accept: 'text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c'
}
Expand Down
22 changes: 11 additions & 11 deletions packages/http-content-negotiation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const httpContentNegotiationMiddleware = (opts = {}) => {
context
)
}

if (options.parseEncodings) {
parseHeader(
'Accept-Encoding',
Expand Down Expand Up @@ -104,16 +103,17 @@ const parseHeader = (
context[resultsName] = parseFn[type](headerValue, availableValues)
context[resultName] = context[resultsName][0]

if (defaultToFirstValue && context[resultName] === undefined) {
context[resultName] = availableValues[0]
}
if (failOnMismatch && context[resultName] === undefined) {
// NotAcceptable
throw createError(
406,
`Unsupported ${type}. Acceptable values: ${availableValues.join(', ')}`,
{ cause: { package: '@middy/http-content-negotiation' } }
)
if (context[resultName] === undefined) {
if (defaultToFirstValue) {
context[resultName] = availableValues[0]
} else if (failOnMismatch) {
// NotAcceptable
throw createError(
406,
`Unsupported ${type}. Acceptable values: ${availableValues.join(', ')}`,
{ cause: { package: '@middy/http-content-negotiation' } }
)
}
}
}

Expand Down

0 comments on commit fa6c1ef

Please sign in to comment.