This is an automated email from the ASF dual-hosted git repository.

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 492fa71  bugfix: added `content-type` for admin API responses (#1746)
492fa71 is described below

commit 492fa71cbc783f47a43e7b7d20b2410f69daba29
Author: Shenal Silva <[email protected]>
AuthorDate: Wed Jun 24 11:27:10 2020 +0530

    bugfix: added `content-type` for admin API responses (#1746)
---
 apisix/init.lua  |  7 +++++++
 t/admin/routes.t | 28 ++++++++++++++++++++++++++--
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/apisix/init.lua b/apisix/init.lua
index 35f6076..2447165 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 be9feb6..05f32dd 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

Reply via email to