![](/img/trans.png)
[英]AWS API Gateway:Mock integration response dynamic header mapping values
[英]AWS Api Gateway mock integration response header mapping, how?
我正在挖掘网络并一直试图找到在以下情况下我缺少的东西:我试图解决的基本问题是:当http://example.com/login?target=http://google.com被调用时,用户被重定向到 OAuth 登录页面,其状态指的是目标查询参数中的 url。
所以: http://example.com/login?target=http://google.com
将被重定向到http://authenticator.com/login?type=...&redirect_uri=...&client_id=...&state=http://google.com
我可以用 Lambda 做到这一点,但我觉得没有必要,可以单独使用 API Gateway。
首先,我创建了/login
资源和一个GET
方法,并向其中添加了一个模拟集成。
我在方法响应中设置了 302:
最后我添加了集成响应:
但是,当我测试该方法时,缺少 Location 标头。 如果我在集成响应中的位置标头中放置一个静态字符串,它会起作用,但是无论我在标头映射中尝试什么,它都不起作用。
我在集成请求映射中尝试过的事情:
{
"statusCode": 200,
"headers": {"target": "https://google.com"}
}
{
"statusCode": 200,
"target": "https://google.com"
}
我似乎integration.response.body.target
或integration.response.header.target
总是空的。 根据文档, headers
属性可以是集成响应的一部分,但我无法从我在集成请求中设置的映射模板中获得任何值。
知道我做错了什么吗?
您可以进行响应覆盖,例如:在您的集成请求中
#set($urlProxy = $method.request.path.proxy)
{
"statusCode": 301,
}
#set($context.responseOverride.header.location = "https://www.foo.bar.com/$urlProxy")
这将覆盖您的响应标头位置
看起来您正在尝试从标头值进行映射,但从未设置标头值,而是在正文中设置了一个名为“标头”的属性。 为了映射来自integration.response.header.target
的值,您需要在集成请求的 HTTP 标头部分的模拟中设置该值。
但是,您可能会发现将模拟的请求映射模板设置为更简单
{ "statusCode": 200, "target": "https://google.com" }
然后您可以使用响应映射将您的Location
标头设置为integration.response.body.target
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.