Skip to content

Commit

Permalink
Pass headers to custom error backend
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Feb 14, 2017
1 parent aa02b7e commit d534d7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions controllers/nginx/rootfs/etc/nginx/lua/error_page.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ local get_upstreams = upstream.get_upstreams
local random = math.random
local us = get_upstreams()

function openURL(status)
function openURL(headers, status)
local httpc = http.new()

headers["X-Code"] = status or "404"
headers["X-Format"] = headers["Accept"] or "html",

local random_backend = get_destination()
local res, err = httpc:request_uri(random_backend, {
path = "/",
method = "GET",
headers = {
["X-Code"] = status or "404",
["X-Format"] = ngx.var.httpAccept or "html",
}
headers = headers,
})

if not res then
ngx.log(ngx.ERR, err)
ngx.exit(500)
end

if ngx.var.http_cookie then
ngx.header["Cookie"] = ngx.var.http_cookie
for k,v in pairs(res.headers) do
ngx.log(ngx.DEBUG, k, ": ", v)
ngx.header[k] = v
end

ngx.status = tonumber(status)
Expand Down
4 changes: 2 additions & 2 deletions controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ http {
location / {
{{ if .CustomErrors }}
content_by_lua_block {
openURL(503)
openURL(ngx.req.get_headers(), 503)
}
{{ else }}
return 503;
Expand Down Expand Up @@ -477,7 +477,7 @@ stream {
location @custom_{{ $errCode }} {
internal;
content_by_lua_block {
openURL({{ $errCode }})
openURL(ngx.req.get_headers(), {{ $errCode }})
}
}
{{ end }}
Expand Down

0 comments on commit d534d7f

Please sign in to comment.