Skip to content

Commit

Permalink
bugfix: added content-type for admin API responses (#1746)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenal authored Jun 24, 2020
1 parent d419fb2 commit 492fa71
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 7 additions & 0 deletions apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ local function cors_admin()
"Access-Control-Max-Age", "3600")
end

local function add_content_type()
core.response.set_header("Content-Type", "application/json")
end

do
local router

Expand All @@ -530,6 +534,9 @@ function _M.http_admin()
-- add cors rsp header
cors_admin()

-- add content type to rsp header
add_content_type()

-- core.log.info("uri: ", get_var("uri"), " method: ", get_method())
local ok = router:dispatch(get_var("uri"), {method = get_method()})
if not ok then
Expand Down
28 changes: 26 additions & 2 deletions t/admin/routes.t
Original file line number Diff line number Diff line change
Expand Up @@ -1773,8 +1773,6 @@ passed
--- no_error_log
[error]



=== TEST 48: string id
--- config
location /t {
Expand Down Expand Up @@ -1858,3 +1856,29 @@ GET /t
--- error_code: 400
--- no_error_log
[error]


=== TEST 50: Verify Response Content-Type=applciation/json
--- config
location /t {
content_by_lua_block {
local http = require("resty.http")
local httpc = http.new()
httpc:set_timeout(500)
httpc:connect(ngx.var.server_addr, ngx.var.server_port)
local res, err = httpc:request(
{
path = '/apisix/admin/routes/1?ttl=1',
method = "GET",
}
)

ngx.header["Content-Type"] = res.headers["Content-Type"]
ngx.status = 200
ngx.say("passed")
}
}
--- request
GET /t
--- response_headers
Content-Type: application/json

0 comments on commit 492fa71

Please sign in to comment.