Lua脚本httpCall并使用response_handle

我有一个envoy路由器,用于从S3存储桶检索静态内容,我使用envoy_on_request请求句柄进行重新路由,并使用envoy.filters.http.aws_request_signing启用请求

如果S3中没有请求的内容/页面/文件,则希望通过从存储桶中获取404 HTML页面的内容来重写响应,为此,我使用以下response_handle检查状态码,如果为404,则进行httpCall以获取404内容,然后将其转储到响应正文中。

下面的代码可以运行,但我得到了默认的S3 XML拒绝访问响应,然后将其作为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
点赞