amazon-web-services - 带有 response_handle 的 Lua 脚本 httpCall
问题描述
我有一个 envoy 路由器,用于从 S3 存储桶中检索静态内容,我使用 envoy_on_request 请求句柄进行重新路由,并使用 envoy.filters.http.aws_request_signing 启用请求
如果请求的内容/页面/文件在 S3 中不可用,那么我想通过从存储桶中的 404 HTML 页面获取内容来重写响应,为此我使用以下 response_handle 检查状态代码,如果是 404,则进行 httpCall 以获取 404 内容,然后将其转储到响应正文中。
下面的代码运行,但是我得到了默认的 S3 XML Access denied 响应,然后将其转储为 html。
获得拒绝访问响应的原因可能是什么?是不是因为envoy内部的这个请求没有签名?如果是这样,如何对 httpCall 进行签名或者它与请求签名无关....
function envoy_on_response(response_handle)
local statusCode = response_handle:headers():get(":status")
if statusCode == '404' then
response_handle:body()
local headers, body = response_handle:httpCall(
's3-envoy-lua-cluster',
{
[":method"] = "GET",
[":path"] = "/notfound/404.html",
[":authority"] = "content-s3-bucket"
},
'',
1000)
local content_length = response_handle:body():setBytes(body)
response_handle:headers():replace("content-length", content_length)
response_handle:headers():replace("content-type", "text/html")
end
end
解决方案
推荐阅读
- com - 如何读取 winmd(WinRT 元数据文件)?
- reactjs - React 和 Express 上的 Stripe 测试返回 404,也没有 console.log req.body
- reactjs - 注销时隐藏注销按钮
- node.js - 在 Node.js 上跨平台开发的路径中,我是否应该始终用正斜杠替换反斜杠?
- asp.net - 来自不同目录的 C# ASP.NET Webform 图像源
- python - 自动排除网络故障
- c - 在 C 中打印 Armstrong 数字
- javascript - 仅有条件地包含 console..log 语句并将它们从 javascript 文件的生产分发中删除
- ember.js - Ember 的 Promise 重试包装器
- tumblr - 使用 Infinite Scroll 使 Tumblr Like 按钮可点击(Dave DeSandro 的 v3)