Skip to content

Commit

Permalink
fix(core) returning appropriate headers in error pages. Closes #1553
Browse files Browse the repository at this point in the history
…and #1552.
  • Loading branch information
subnetmarco committed Aug 30, 2016
1 parent e1a8da0 commit f84216b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
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)

0 comments on commit f84216b

Please sign in to comment.