gpt4 book ai didi

aws-lambda - API Gateway 结合 Lambda 集成和 CloudFront 忽略多个 Set-Cookie header

转载 作者:行者123 更新时间:2023-12-04 11:35:36 24 4
gpt4 key购买 nike

我的设置如下所示:

|––––––––––––|                  |–––––––––––––|     |–––––––––––––––––|
| | <- origin 1 -> | API Gateway | <-> | Lambda function |
| | |–––––––––––––| |–––––––––––––––––|
| CloudFront |
| | |–––––––––––––|
| | <- origin 2 -> | S3 bucket |
|––––––––––––| |–––––––––––––|
我需要在 API 网关前面使用 CloudFront 才能获得自动 http->https 重定向。
我正在使用自定义 login.example.com带有 CloudFront 的子域。
API Gateway 生成的 URL 是 CloudFront 分配的源 1。
这一切都按预期工作。
我什至可以返回一个 Set-Cookie来自 lambda 函数的 header ,它将被传递,直到它到达浏览器。
{
"statusCode": 302,
"body": "",
"headers": {
"location": "/test",
"surrogate-control": "no-store",
"cache-control": "no-store, no-cache, must-revalidate, proxy-revalidate",
"pragma": "no-cache",
"expires": "0",
"content-length": "0",
"date": "Fri, 19 Feb 2021 17:25:56 GMT",
"connection": "keep-alive",
"set-cookie": "cookie1=68abcdbefbef7d84c26e68; Max-Age=2592000; Domain=example.com; Path=/; HttpOnly; Secure; SameSite=Strict"
},
"isBase64Encoded": false
}
添加另一个不起作用 - 正如您查看文档时所预期的那样:
  • https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#apigateway-multivalue-headers-and-parameters
  • https://aws.amazon.com/blogs/compute/support-for-multi-value-parameters-in-amazon-api-gateway/

  • {
    "statusCode": 302,
    "headers": {
    "location": "/test",
    "set-cookie": [
    "cookie1=68abcdbefbef7d84c26e68; Max-Age=2592000; Domain=example.com; Path=/; HttpOnly; Secure; SameSite=Strict",
    "cookie2-login=; Max-Age=0; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure"
    ],
    "surrogate-control": "no-store",
    "cache-control": "no-store, no-cache, must-revalidate, proxy-revalidate",
    "pragma": "no-cache",
    "expires": "0",
    "content-length": "0"
    }
    }
    这两个都将被忽略/删除。
    但即使我使用的是 multiValueHeaders对象返回多个相同类型,如下所示:
    {
    "statusCode": 302,
    "body": "",
    "headers": {
    "location": "/test",
    "surrogate-control": "no-store",
    "cache-control": "no-store, no-cache, must-revalidate, proxy-revalidate",
    "pragma": "no-cache",
    "expires": "0",
    "content-length": "0",
    "date": "Fri, 19 Feb 2021 17:25:56 GMT",
    "connection": "keep-alive"
    },
    "isBase64Encoded": false,
    "multiValueHeaders": {
    "Set-Cookie": [
    "cookie1=68abcdbefbef7d84c26e68; Max-Age=2592000; Domain=example.com; Path=/; HttpOnly; Secure; SameSite=Strict",
    "cookie2-login=; Max-Age=0; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; Secure"
    ]
    }
    }
    API 网关从它传递给 CloudFront 的响应中删除/忽略它们。
    我究竟做错了什么?
    使用 multiValueHeaders 时是否必须在 API 网关中映射某些内容? ?
    正常 headers['set-cookie']自动传递但 multiValueHeaders不是?
    附加属性有问题吗?
    我试图为根域而不是 login.example.com 域设置 cookie 是否有问题?

    最佳答案

    终于自己找到了答案:
    新的负载格式 (2.0) 不支持 multiValueHeaders .

    Working with AWS Lambda proxy integrations for HTTP APIs

    [...] Format 2.0 doesn't have multiValueHeaders or multiValueQueryStringParameters fields. Duplicate headers are combined with commas and included in the headers field. Duplicate query strings are combined with commas and included in the queryStringParameters field. [...]

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


    所以我正在重写 set-cookie不同拼写的标题:
    Set-cookie
    sEt-cookie
    seT-cookie
    在出现 multiValueHeaders 之前,您必须这样做。 - 但它似乎仍然是你使用新的有效载荷格式的唯一方法:(

    关于aws-lambda - API Gateway 结合 Lambda 集成和 CloudFront 忽略多个 Set-Cookie header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66284664/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com