首页 > 解决方案 > 带有 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

标签: amazon-web-servicesamazon-s3httpsluaenvoyproxy

解决方案


推荐阅读