Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core) returning appropriate headers in error pages #1567

Merged
merged 1 commit into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion kong/core/error_handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ local xml_template = '<?xml version="1.0" encoding="UTF-8"?>\n<error><message>%s
local html_template = '<html><head><title>Kong Error</title></head><body><h1>Kong Error</h1><p>%s.</p></body></html>'

local BODIES = {
s404 = "Not found",
s408 = "Request timeout",
s411 = "Length required",
s412 = "Precondition failed",
s413 = "Payload too large",
s414 = "URI too long",
s417 = "Expectation failed",
s500 = "An unexpected error occurred",
s502 = "An invalid response was received from the upstream server",
s503 = "The upstream server is currently unavailable",
Expand Down Expand Up @@ -48,4 +55,4 @@ return function(ngx)
ngx.header["Server"] = SERVER_HEADER
ngx.header["Content-Type"] = content_type
ngx.say(format(template, message))
end
end
7 changes: 4 additions & 3 deletions kong/templates/nginx_kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ init_worker_by_lua_block {
server {
server_name kong;
listen ${{PROXY_LISTEN}};
error_page 500 502 503 504 /50x;
error_page 404 408 411 412 413 414 417 /kong_error_handler;
error_page 500 502 503 504 /kong_error_handler;

> if ssl then
listen ${{PROXY_LISTEN_SSL}} ssl;
Expand Down Expand Up @@ -100,7 +101,7 @@ server {
}
}

location = /50x {
location = /kong_error_handler {
internal;
content_by_lua_block {
require('kong.core.error_handlers')(ngx)
Expand Down Expand Up @@ -140,4 +141,4 @@ server {
return 200 'User-agent: *\nDisallow: /';
}
}
]]
]]
3 changes: 2 additions & 1 deletion spec/02-integration/05-proxy/01-resolver_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,5 +358,6 @@ describe("Resolver", function()
}
})
assert.res_status(414, res)
assert.match(meta._NAME.."/"..meta._VERSION, res.headers["server"])
end)
end)
end)