Skip to content

Commit

Permalink
Merge pull request #275 from aledbf/pass-headers
Browse files Browse the repository at this point in the history
Pass headers to custom error backend
  • Loading branch information
aledbf authored Feb 14, 2017
2 parents a9b5770 + 0cdc4bd commit a8b8967
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 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,26 @@ local get_upstreams = upstream.get_upstreams
local random = math.random
local us = get_upstreams()

function openURL(status)
function openURL(original_headers, status)
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 res, err = httpc:request_uri(random_backend, {
path = "/",
method = "GET",
headers = {
["X-Code"] = status or "404",
["X-Format"] = ngx.var.httpAccept or "html",
}
headers = original_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.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(0), 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(0), {{ $errCode }})
}
}
{{ end }}
Expand Down

0 comments on commit a8b8967

Please sign in to comment.