【问题标题】:How to return multiple cookies with AWS APIGateway and Lambda?如何使用 AWS APIGateway 和 Lambda 返回多个 cookie?
【发布时间】:2018-09-30 17:12:43
【问题描述】:

我正在尝试通过 APIGateway 从 Lambda 向客户端(邮递员)返回两个 cookie。 我参考了aws博客,可以返回1个cookie给客户端。

https://aws.amazon.com/jp/blogs/compute/simply-serverless-using-aws-lambda-to-expose-custom-cookies-with-api-gateway/

但我不知道要返回 2 种 cookie。 我试过这样,但没有工作。

return {
   'cookie': 'aaa=bbb; secure'               -> Okay, but just one cookie
    # 'cookie': 'aaa=bbb; ccc=ddd; secure'   -> ×
    # 'cookie': ['aaa=bbb','ccc=ddd']        -> ×
}

谁能给我一个建议?

【问题讨论】:

标签: python amazon-web-services aws-lambda aws-api-gateway serverless-framework


【解决方案1】:

据我所知,您不能在同一个 Set-Cookie 标头中设置多个 cookie。网上有文献说可以,但我在 API Gateway 中复制的尝试没有结果。

此外,在撰写本文时,API Gateway 不允许您设置多个 Set-Cookie 标头。 This has been a long-requested and still not implemented feature.

如果可以的话,我建议将您的所有信息打包到一个对象中,并在一个 cookie 中发送 JSON。


如果你真的需要,这里有一个恶心的解决方法...

API Gateway 的响应标头区分大小写,因此您可以通过改变大小写来定义 set-cookie 标头的多个实例,如下所示:

Set-Cookie
SET-COOKIE
SeT-CoOkIe

【讨论】:

    【解决方案2】:

    使用响应头 Set-Cookie 和映射值“integration.response.multivalueheader.Set-Cookie”设置映射

    来源“https://medium.com/nirman-tech-blog/aws-gateway-api-endpoints-multi-value-cookie-mapping-a36586cebd5e”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-11
      • 2022-07-28
      • 1970-01-01
      • 2017-01-07
      • 1970-01-01
      • 2021-09-20
      • 2018-03-23
      • 2021-05-14
      相关资源
      最近更新 更多