Skip to content

Commit

Permalink
fix(azure-function): handle single or multiple cookies at once (#525)
Browse files Browse the repository at this point in the history
* Fix Azure Cookie - Handle single or multiple cookies at once

headers['set-cookie'] can be a string of one cookie, or an array of cookies
headerCookies should always be an array

* Fix tests - No more "response.cookies: []" when no cookie

Sorry about that

Co-authored-by: Brett Andrews <brett.j.andrews@gmail.com>
  • Loading branch information
XavM and brettstack authored Jun 7, 2022
1 parent c630868 commit d10f49a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/event-sources/azure/http-function-runtime-v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ function getResponseToHttpFunction ({ statusCode, body, headers = {}, isBase64En
}

const cookies = []
const headerCookies = headers['set-cookie']

// headers['set-cookie'] can be a string of one cookie, or an array of cookies
// headerCookies should always be an array
const headerCookies = [].concat(headers['set-cookie'] || [])

// Convert 'set-cookie' to Azure Function 3.x cookie object array
// https://github.com/Azure/azure-functions-nodejs-worker/blob/v3.x/types/index.d.ts#L150
if (headerCookies) {
if (headerCookies.length > 0) {
for (const headerCookie of headerCookies) {
const parsedCookie = parseCookie(headerCookie)
const nameValueTuple = headerCookie.split(';')[0].split('=')
Expand Down

0 comments on commit d10f49a

Please sign in to comment.