使用AWS Gateway API,我可以访问cookie吗? [英] Using AWS Gateway API, can I access the cookies?

查看:460
本文介绍了使用AWS Gateway API,我可以访问cookie吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用HTTP代理集成,我想访问cookie并将其添加到json响应中.有可能吗?

Using a HTTP Proxy Integration I want to access the cookies and add one to the json response. Is that possible?

推荐答案

要访问客户端在后端发送的cookie,您必须设置从方法请求标头到集成请求标头的映射.

To access cookies sent by the client in your backend you'll have to setup a mapping from the method request header to your integration request header.

这些说明假设您已经在API Gateway中设置了一个简单的方法.

These instructions assume you've already setup a simple method in API Gateway.

访问您后端中的Cookie

  1. 在方法请求"下,创建一个名称为"Cookie"的HTTP请求标头
  2. 在集成请求"下,创建一个名称为"Cookie"且映射自"值为method.request.header.Cookie的HTTP标头.
  3. 您可能还需要为此方法设置CORS.请参阅: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html
  4. 部署您的API并使用您的浏览器/客户端向您的API Gateway端点发出请求.您应该会看到带有浏览器发送的Cookie标头值的请求进入HTTP后端.
  1. Under Method Request, create an HTTP Request Header with the name of "Cookie"
  2. Under Integration Request, create an HTTP header with name "Cookie" and "Mapped from" value of method.request.header.Cookie.
  3. You'll also likely need to setup CORS for this method. See: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html
  4. Deploy your API and make a request to your API Gateway endpoint with your browser/client. You should see requests coming in to your HTTP backend with the Cookie header value sent from the browser.

向响应添加cookie

您可以类似的方式为方法配置的集成响应/方法响应端设置Set-Cookie响应标头.

You can setup a Set-Cookie response header in an analogous fashion for the the integration response/method response side of the method configuration.

  1. 在方法响应"下,创建一个名称为Set-Cookie
  2. 的响应标头
  3. 在Integration Response下,设置带有Response标头Set-Cookie和映射值integration.response.header.Set-Cookie
  4. 的标头映射
  1. Under Method Response, create a Response header with name Set-Cookie
  2. Under Integration Response setup a Header Mapping with Response header Set-Cookie and Mapping value integration.response.header.Set-Cookie

请注意,目前,API Gateway仅支持设置单个Set-Cookie响应标头.如果您的后端尝试设置多个Set-Cookie标头,则仅设置最后一个.请参阅此论坛帖子以获取更多详细信息: https://forums.aws.amazon.com/thread.jspa?messageID=701434

Please note that at this time, API Gateway supports setting just a single Set-Cookie response header. If your backend attempts to set multiple Set-Cookie headers, only the last one will be set. See this forum post for more details: https://forums.aws.amazon.com/thread.jspa?messageID=701434

这篇关于使用AWS Gateway API,我可以访问cookie吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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