wingleung / remix-aws

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

Not setting multiple headers #13

Open MattyBalaam opened 2 months ago

MattyBalaam commented 2 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 2 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}`
                }
            }
        )