Skip to content

Commit d10f49a

Browse files
XavMbrettstack
andauthored
fix(azure-function): handle single or multiple cookies at once (#525)
* 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 <[email protected]>
1 parent c630868 commit d10f49a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/event-sources/azure/http-function-runtime-v3.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ function getResponseToHttpFunction ({ statusCode, body, headers = {}, isBase64En
4242
}
4343

4444
const cookies = []
45-
const headerCookies = headers['set-cookie']
46-
45+
// headers['set-cookie'] can be a string of one cookie, or an array of cookies
46+
// headerCookies should always be an array
47+
const headerCookies = [].concat(headers['set-cookie'] || [])
48+
4749
// Convert 'set-cookie' to Azure Function 3.x cookie object array
4850
// https://github.com/Azure/azure-functions-nodejs-worker/blob/v3.x/types/index.d.ts#L150
49-
if (headerCookies) {
51+
if (headerCookies.length > 0) {
5052
for (const headerCookie of headerCookies) {
5153
const parsedCookie = parseCookie(headerCookie)
5254
const nameValueTuple = headerCookie.split(';')[0].split('=')

0 commit comments

Comments
 (0)