简体   繁体   English

具有Lambda代理的API网关Set-Cookie

[英]API Gateway Set-Cookie with Lambda Proxy

I'm trying to set a cookie from Lambda which goes through API Gateway and it just doesn't seem to be sent through. 我正在尝试通过Lambda设置一个Cookie,该Cookie会通过API网关,但似乎并没有通过它发送。

This is what I've tried sending: 这是我尝试发送的内容:

{
  body: JSON.stringify({}),
  headers: {
     'Access-Control-Allow-Origin': '*',
     'Access-Control-Allow-Headers': '*',
     'Access-Control-Allow-Credentials': true,
     'test': 'test',
     'Set-Cookie': 'name=test',
  }
}

All of the other headers are showing up in chrome under response headers, except the cookie. 除cookie之外,其他所有标头均以chrome形式显示在响应标头下。 I've tried adding Set-Cookie to the Method Reponse for 200 , but this made no difference. 我尝试将Set-Cookie添加到200的方法响应中,但这没什么区别。

Any ideas how to get this to work? 任何想法如何使它起作用? Thank you! 谢谢!

Your code looks good as following sample is working fine to set cookies 您的代码看起来不错,因为以下示例可以很好地设置Cookie

setcookies : setcookies:

 {
  "statusCode": 200,
  "body": "testing set-cookie headers",
  "headers": {
    "X-Test-Header": "vaquarkhan experiment",
    "Set-Cookie": "cookie2=vaquarkhan",
    "Content-Type": "text/plain"
  }
}

or 要么

   Set-Cookie header to integration.response.header.Set-Cookie

You can set cookes using console and check into devloper tools 您可以使用控制台设置厨师并检查开发者工具

Steps : On Api gateay Method page, choose Integration Response. 步骤:在“ Api Gateay方法”页面上,选择“积分响应”。 Under the Header Mappings section of the default 200 HTTP status, choose the pencil icon to edit the “Set-Cookie” header. 在默认的200 HTTP状态的“标题映射”部分下,选择铅笔图标以编辑“ Set-Cookie”标题。 In the mapping value section, put: 在映射值部分,输入:

integration.response.body.Cookie 集成响应正文Cookie

在此处输入图片说明

Now next step choose Integration Response. 现在,下一步选择集成响应。 Under the Header Mappings section of the default 200 HTTP status, choose the pencil icon to edit the “Set-Cookie” header. 在默认的200 HTTP状态的“标题映射”部分下,选择铅笔图标以编辑“ Set-Cookie”标题。 In the mapping value section. 在映射值部分。

在此处输入图片说明

Now debug - Can you use following link and share what can see in devtools for cookies - https://developers.google.com/web/tools/chrome-devtools/storage/cookies 现在进行调试-您可以使用以下链接并共享在devtools中看到的cookie吗-https: //developers.google.com/web/tools/chrome-devtools/storage/cookies

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM