Skip to content

Commit

Permalink
better support for duplicate headers for format 2.0, shoud fix #125
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Sep 6, 2022
1 parent f509a5c commit bbea18c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,19 @@ module.exports = (app, options) => {
} else if (event.queryStringParameters) {
Object.keys(event.queryStringParameters).forEach((q) => {
query[decodeURIComponent(q)] = decodeURIComponent(event.queryStringParameters[q])
if (typeof query[decodeURIComponent(q)] === 'string' && query[decodeURIComponent(q)].indexOf(',') > 0) {
query[decodeURIComponent(q)] = query[decodeURIComponent(q)].split(',')
}
})
}
} else {
if (event.queryStringParameters) {
Object.keys(event.queryStringParameters).forEach((k) => {
if (typeof event.queryStringParameters[k] === 'string' && event.queryStringParameters[k].indexOf(',') > 0) {
event.queryStringParameters[k] = event.queryStringParameters[k].split(',')
}
})
}
Object.assign(query, event.multiValueQueryStringParameters || event.queryStringParameters)
}
const headers = Object.assign({}, event.headers)
Expand Down
20 changes: 20 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@ test('GET with multi-value query params', async (t) => {
t.equal(ret.body, '{"foo":["qux","bar"]}')
})

test('GET with multi-value query params (queryStringParameters)', async (t) => {
t.plan(2)

const app = fastify()
app.get('/test', async (request, reply) => {
reply.send(request.query)
})
const proxy = awsLambdaFastify(app)

const ret = await proxy({
httpMethod: 'GET',
path: '/test',
queryStringParameters: {
foo: 'qux,bar'
}
})
t.equal(ret.statusCode, 200)
t.equal(ret.body, '{"foo":["qux","bar"]}')
})

test('GET with double encoded query value', async (t) => {
t.plan(2)

Expand Down

0 comments on commit bbea18c

Please sign in to comment.