wingleung / remix-aws

AWS adapter for Remix
https://www.npmjs.com/package/remix-aws
MIT License
23 stars 5 forks source link

Not setting multiple headers #13

Open MattyBalaam opened 7 months ago

MattyBalaam commented 7 months ago

Following the pattern outlined here of setting multiple headers works in local node environment: https://github.com/remix-run/remix/issues/231

   return json(
            { success: true },
            {
                headers: [
                    ["Set-Cookie", await commiSession1()],
                    ["Set-Cookie", await commiSession2()]

                ]
            }
        )

However, when running using the createRequestHandler from this package (only tried using AWSProxy.APIGatewayV1) only the last cookie is set.

Looking at the code it may be because you are not returning multiValueHeaders, just headers

https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html

wingleung commented 7 months ago

@MattyBalaam hmm I would expect remix to return a valid Headers object, which would mean it should return the following

HeadersList {
  cookies: [ 'cookie1=value1', 'cookie2=value2' ],
  [Symbol(headers map)]: Map(1) {
    'set-cookie' => { name: 'Set-Cookie', value: 'cookie1=value1, cookie2=value2' }
  },
  [Symbol(headers map sorted)]: null
}

👉 https://replit.com/@wingleung1/UnripeSunnyProgrammers

But what I receive from remix is an object containing an array value in headers, which is not compliant with the apigwV1 model

headers: {
  'content-type': 'text/html',
  'set-cookie': [ 'cookie1=chocolate-chip', 'cookie2=oatmeal' ]
}

Created a PR with a workaround 👉 #15

meantime, could you try using comma delimiters?

   const session1 = await commiSession1()
   const session2 = await commiSession2()

   return json(
            { success: true },
            {
                headers: {
                    "Set-Cookie": `${session1}, ${session2}`
                }
            }
        )
wingleung commented 1 month ago

🙏 merged to develop and published a beta version 👉 1.3.0-beta.1