Merge pull request #275 from aledbf/pass-headers
Pass headers to custom error backend
This commit is contained in:
commit
a8b89677d6
2 changed files with 9 additions and 9 deletions
|
@ -8,17 +8,17 @@ local get_upstreams = upstream.get_upstreams
|
||||||
local random = math.random
|
local random = math.random
|
||||||
local us = get_upstreams()
|
local us = get_upstreams()
|
||||||
|
|
||||||
function openURL(status)
|
function openURL(original_headers, status)
|
||||||
local httpc = http.new()
|
local httpc = http.new()
|
||||||
|
|
||||||
|
original_headers["X-Code"] = status or "404"
|
||||||
|
original_headers["X-Format"] = original_headers["Accept"] or "text/html"
|
||||||
|
|
||||||
local random_backend = get_destination()
|
local random_backend = get_destination()
|
||||||
local res, err = httpc:request_uri(random_backend, {
|
local res, err = httpc:request_uri(random_backend, {
|
||||||
path = "/",
|
path = "/",
|
||||||
method = "GET",
|
method = "GET",
|
||||||
headers = {
|
headers = original_headers,
|
||||||
["X-Code"] = status or "404",
|
|
||||||
["X-Format"] = ngx.var.httpAccept or "html",
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if not res then
|
if not res then
|
||||||
|
@ -26,8 +26,8 @@ function openURL(status)
|
||||||
ngx.exit(500)
|
ngx.exit(500)
|
||||||
end
|
end
|
||||||
|
|
||||||
if ngx.var.http_cookie then
|
for k,v in pairs(res.headers) do
|
||||||
ngx.header["Cookie"] = ngx.var.http_cookie
|
ngx.header[k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
ngx.status = tonumber(status)
|
ngx.status = tonumber(status)
|
||||||
|
|
|
@ -407,7 +407,7 @@ http {
|
||||||
location / {
|
location / {
|
||||||
{{ if .CustomErrors }}
|
{{ if .CustomErrors }}
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
openURL(503)
|
openURL(ngx.req.get_headers(0), 503)
|
||||||
}
|
}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
return 503;
|
return 503;
|
||||||
|
@ -477,7 +477,7 @@ stream {
|
||||||
location @custom_{{ $errCode }} {
|
location @custom_{{ $errCode }} {
|
||||||
internal;
|
internal;
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
openURL({{ $errCode }})
|
openURL(ngx.req.get_headers(0), {{ $errCode }})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in a new issue