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

Added content-type admin API responses #1746

Merged
merged 3 commits into from
Jun 24, 2020
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
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