在AWS Lambda Node JS的http响应标头中设置Cookie [英] Setting Cookie in http response header from AWS lambda Node JS

查看:112
本文介绍了在AWS Lambda Node JS的http响应标头中设置Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我启用了Lambda代理集成,并将响应标头设置为Lambda输出和API网关的一部分,并将它们作为对客户端的HTTP响应的一部分返回.

I have a Lambda proxy integration enabled, and setting the response headers as part of Lambda output and API Gateway that will return them as part of the HTTP response to the client.

示例代码:

callback(null, {
    "statusCode": 302,
    "Location" : "https://somewebsite.com"
    "headers": { "headerName": "headerValue", ... },
    "body": "..."
});

我需要在标题中发送3个cookie.我试过了.但是,失败了:

I need to send out 3 cookies in the headers. I tried. But, failed:

callback(null, {
    "statusCode": 302,
    "Location" : "https://somewebsite.com"
    "headers": { "Set-Cookie": [cookie1String, cookie2String, cookie3String] },
    "body": "..."
});

我将cookie连接起来并作为响应传递,客户端获取了cookie.但是,当客户端在位置"中调用目标时,请求的标头中就没有cookie.

I concatenated the cookie and passed in as the response, the client gets the cookie. But when the client calls the target in "location", the request does not have the cookie in the header.

callback(null, {
    "statusCode": 302,
    "Location" : "https://somewebsite.com"
    "headers": { "Set-Cookie": c1=cookie1String;c2=cookie2String; c3=cookie3String] },
    "body": "..."
});

请帮助将这3个Cookie发送给我的客户.

Please help in sending these 3 cookies out to my client.

推荐答案

API网关不允许您多次映射同一标头.我通过使用不同的大小写设置cookie方法来解决这个问题.

API gateway does not let you map the same header more than once. I got around by using different casing to set-cookie method.

callback(null, {
    "statusCode": 302,
    "Location" : "https://somewebsite.com"
    "headers": { "Set-Cookie": cookie1, "set-Cookie": cookie2 },
    "body": "..."
});

这篇关于在AWS Lambda Node JS的http响应标头中设置Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆