如何使用代理的Lambda从API网关发送多个Set-Cookie标头

问题描述:

我正在使用API​​ Gateway的代理集成来调用Lambda.输出格式规范如下JSON格式:

I'm using API Gateway's Proxy integration to call a Lambda. The output format specification is this follow JSON format:

{
  "statusCode": httpStatusCode,
  "headers": { "headerName": "headerValue", ... },
  "body": "..."
}

在一个响应中,我希望设置两个cookie(两个不同的auth cookie),但是JSON不允许在headers对象中具有两个相同的键(好的,从技术上讲规范是这样做的,但是大多数库都没有).

In one response I wish to set two cookies (two different auth cookies) but JSON doesn't allow having two identical keys in the headers object (OK, technically the spec does but most libraries do not).

RFC 7230 指出Set-Cookie应该特别处理,但我看不到如何通过API网关发送多个Set-Cookie值.

RFC 7230 notes that Set-Cookie should be handled specially but I can't see how I can send multiple Set-Cookie values through API gateway.

有人知道这是否可能吗?

Does anyone know whether this is possible?

对此进行了实验,我得出结论认为目前尚不可能(如果我从AWS支持部门获得其他反馈,将会进行更新).

Having experimented with this I've concluded that it isn't currently possible (will update if I hear back otherwise from AWS support).

我尝试发送以下手动策划的JSON作为响应:

I've tried sending the following manually curated JSON as a response:

{
  "statusCode": 200,
  "body": "testing multiple set-cookie headers",
  "headers": {
    "X-Test-Header": "baking experiment",
    "Set-Cookie": "cookie1=chocolate-chip",
    "Set-Cookie": "cookie2=oatmeal",
    "Content-Type": "text/plain"
  }
}

API网关响应CURL请求而返回的cookie是:

The cookies that API gateway returns in response to a CURL request are:

< Content-Type: text/plain
< Content-Length: 35
< Connection: keep-alive
< Date: Thu, 29 Sep 2016 11:22:09 GMT
< Set-Cookie: cookie2=oatmeal
< X-Test-Header: baking experiment
< X-Cache: Miss from cloudfront

如您所见,第一个Set-Cookie掉在了地板上.

As you can see the first Set-Cookie is dropped on the floor.

理想情况下,JSON输出格式中的标头的JSON格式应类似于:

Ideally the JSON format for the headers in the JSON output format should be something like:

{
  "statusCode": httpStatusCode,
  "headers": [
    { "headerName": "headerValue" },
    ...
  ],
  "body": "..."
}