Multiple `Set-Cookie` headers cause netlify lambda to throw an error

Our netlify lambda works flawlessly on netlify dev mode, but when deployed with CI, it works only partially: it does return the proper responses for our requests, but it comes with 502 status, and its’ Set-Cookie header is empty.

The netlify function logs shows something like this:

3:10:10 PM: proxy invoked
3:10:10 PM: error decoding lambda response: json: cannot unmarshal array into Go value of type string

This is probably because we’re sending header that has a value which is an array.

For example: { headers: { 'Set-Cookie': ['a', 'b'] } }

Before this, we were sending them as { 'set-cookie': a, 'Set-cookie': b, 'sEt-cookie': c } (because that’s how serverless-http handles it - https://github.com/dougmoscrop/serverless-http/pull/16 ), but when deployed to Netlify, responses were coming back with only one (the last one) set-cookie header ("c"). It appeared like Netlify was case insensitive when looking at the header keys and was skipping the first two "a" and "b" header values.

How can we send multiple Set-Cookie headers with netlify function?

We need this for our proxy server running with netlify.

FYI, I just received such message from support of Netlify:

Hi Jack,

Sorry to say there isn’t a workaround for this at the moment. We aren’t using AWS API gateway, we’re using our own. Right now there isn’t a way to return multiple set-cookie headers from a serverless function.

Gerald from Netlify

Which is quite terrible information… aws lambda allows to send multiple Set-Cookie headers with workaround like this https://github.com/dougmoscrop/serverless-http/pull/16 , but it seems like there is no workaround for Netlify lambdas at the moment.

If anybody finds a way to send multiple cookies in one lambda response, let us know here!

Recent news: after I asked Netlify Support if they plan to fix it, they replied me with the following:

We currently don’t have that on our roadmap but we can file a feature request for you and let you know once it is implemented.

Which means until they plan to take it on their roadmap, pick up the ticket, implement it and deploy it, we’re on our own with this problem… ;/

If anybody else meets that problem, please message them about it - it will increase the chance that they’ll pick it up sooner.

Hi @jtom,

I got an issue filed on this for our team to work on. I don’t think this was implemented in this manner intentionally, I believe it’s more of a side-effect than anything else. As soon as I have more info I’ll update this thread, but I don’t know when that’ll be.

Shameless plug: We’re hiring platform engineers right now

1 Like

I’m cross-referencing: Go lambdas: differences with AWS lambdas prevents me from using algnhsa