diff --git a/apisix/init.lua b/apisix/init.lua index 35f60765624b..24471652295b 100644 --- a/apisix/init.lua +++ b/apisix/init.lua @@ -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 @@ -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 diff --git a/t/admin/routes.t b/t/admin/routes.t index be9feb6a1b4e..05f32dd312e8 100644 --- a/t/admin/routes.t +++ b/t/admin/routes.t @@ -1773,8 +1773,6 @@ passed --- no_error_log [error] - - === TEST 48: string id --- config location /t { @@ -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