将所有标题传递给后续的http调用Lua

时间:2018-02-27 04:33:53

标签: nginx lua

我有lua代码来调用微服务。现在我用

local requestId = ngx.req.get_headers()['X-Request-Id']
local host = ngx.req.get_headers()['Host']
local xForwardedProto = ngx.req.get_headers()['X-Forwarded-Proto']
local xForwardedPort = ngx.req.get_headers()['X-Forwarded-Port']
local xForwardedFor = ngx.req.get_headers()['X-Forwarded-For']
local xRealIP = ngx.req.get_headers()['X-Real-IP']

#####and some logic after that call####

local res = httpc:request_uri(targetURL, {
    method = "GET",
    ssl_verify = false,
    headers = {
        ["Authorization"] = "Bearer " .. ngx.var.unique_token,
        ["X-Request-Id"] = requestId,
        ["Cache-Control"] = ngx.req.get_headers()['Cache-Control']
    }
})

如何在不知道标题名称的情况下以编程方式传递所有标题?

0 个答案:

没有答案