Support websocket request forwarding 89/33989/1
authorHuabingZhao <zhao.huabing@zte.com.cn>
Mon, 5 Mar 2018 06:59:44 +0000 (14:59 +0800)
committerHuabingZhao <zhao.huabing@zte.com.cn>
Mon, 5 Mar 2018 07:00:54 +0000 (15:00 +0800)
Issue-ID: MSB-156
Change-Id: Id63da46c6321d5d007e8078847ad093aaebe0a45
Signed-off-by: HuabingZhao <zhao.huabing@zte.com.cn>
24 files changed:
openresty-ext/src/assembly/resources/openresty/nginx/luaext/conf/msbinit.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/conf/svcconf.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/core/error_handler.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/core/peerwatcher.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/dao/dao.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/dao/db_access.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/dao/redis_db.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/tools/db_cache.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/tools/rr_cache.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/error_handler.lua [deleted file]
openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/log_util.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/table_util.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/peerwatcher.lua [deleted file]
openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/policy/roundrobin.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/base_plugin.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/config_custom.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/redirect-transformer/handler.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/plugins/sampleplugin/handler.lua
openresty-ext/src/assembly/resources/openresty/nginx/luaext/rewrite/commonrewrite.lua [deleted file]
openresty-ext/src/assembly/resources/openresty/nginx/luaext/rewrite/customrewrite.lua [deleted file]
openresty-ext/src/assembly/resources/openresty/nginx/msb-enabled/location-ext/defaultpage.conf [deleted file]
openresty-ext/src/assembly/resources/openresty/run.sh
openresty-ext/src/assembly/resources/openresty/run4docker.sh
openresty-ext/src/assembly/resources/openresty/stop.sh

index ec7d7b0..195cc72 100644 (file)
@@ -1,6 +1,6 @@
 --[[
 
-    Copyright (C) 2018 ZTE, Inc. and others. All rights reserved. (ZTE)
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
index df6356e..8c464dc 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
index f21f10a..a3f6a23 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
index 6b7e522..916d0e1 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
index 8a69499..2adc3fc 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
index 35572cc..11439d9 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
index d35cb8e..cdb72ae 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
index 7f40590..c4d2bb5 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
index bfcc157..45a2b3d 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/error_handler.lua b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/lib/utils/error_handler.lua
deleted file mode 100644 (file)
index 784eb86..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
---[[\r
-\r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
-\r
-    Licensed under the Apache License, Version 2.0 (the "License");\r
-    you may not use this file except in compliance with the License.\r
-    You may obtain a copy of the License at\r
-\r
-            http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-    Unless required by applicable law or agreed to in writing, software\r
-    distributed under the License is distributed on an "AS IS" BASIS,\r
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-    See the License for the specific language governing permissions and\r
-    limitations under the License.\r
-\r
---]]\r
-\r
-local _M = {}\r
-_M._VERSION = '1.0.0'\r
-local msbConf   =  require('conf.msbinit')\r
-local enablefullsearch = msbConf.systemConf.enablefullsearch\r
-local ngx_var = ngx.var\r
-local error_page_head = '<html><head><title>502 Bad Gateway</title></head><body bgcolor="white"><center><h1>502 Bad Gateway</h1></center><center>error message:'\r
-local error_page_foot = '</center><hr><center>nginx</center></body></html>'\r
-local upstream_not_found_err = "service info is incorrect:using own upstream flag is on but upstream name is empty"\r
-\r
-function _M.svc_not_found(err_info,detail_info)\r
-       ngx.log(ngx.WARN, ngx.var.request_id.." "..(err_info or "").." detail_info:"..(detail_info or ""))\r
-       if enablefullsearch and ngx_var.svc_type ~= "custom" then\r
-               -- test against the custom services after the commonrewrite phase\r
-               --ngx.status = ngx.HTTP_GONE\r
-               return ngx.exec("@commonnotfound");\r
-       else\r
-               ngx.status = ngx.HTTP_BAD_GATEWAY\r
-               ngx.print(error_page_head..err_info..error_page_foot)\r
-       end\r
-       return ngx.exit(ngx.status)\r
-end\r
-\r
-function _M.upstream_not_found()\r
-       ngx.log(ngx.WARN, ngx.var.request_id.." "..upstream_not_found_err)\r
-       ngx.status = ngx.HTTP_BAD_GATEWAY\r
-       ngx.print(error_page_head..upstream_not_found_err..error_page_foot)\r
-       return ngx.exit(ngx.status)\r
-end\r
-\r
-return _M
\ No newline at end of file
index 67b0e26..744b14c 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
index c1ddbfe..0e3d853 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/peerwatcher.lua b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/peerwatcher.lua
deleted file mode 100644 (file)
index 6b7e522..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
---[[\r
-\r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
-\r
-    Licensed under the Apache License, Version 2.0 (the "License");\r
-    you may not use this file except in compliance with the License.\r
-    You may obtain a copy of the License at\r
-\r
-            http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-    Unless required by applicable law or agreed to in writing, software\r
-    distributed under the License is distributed on an "AS IS" BASIS,\r
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-    See the License for the specific language governing permissions and\r
-    limitations under the License.\r
-\r
---]]\r
-\r
-local _M = {\r
-       _VERSION = '1.0.0',\r
-       STATUS_OK = 0, STATUS_UNSTABLE = 1, STATUS_ERR = 2\r
-}\r
-local msbConf   =  require('conf.msbinit')\r
-local str_format    = string.format\r
-local now           = ngx.now\r
-local fail_timeout = msbConf.server.fail_timeout or 10\r
-local max_fails = msbConf.server.max_fails  or 1\r
-\r
-local cluster_status = {}\r
-_M.cluster_status = cluster_status\r
-\r
-function _M.is_server_ok(skey, srv)\r
-       return _M.get_srv_status(skey, srv)==_M.STATUS_OK\r
-end\r
-\r
-function _M.get_srv_status(skey, srv)\r
-       local server_status = cluster_status[skey]\r
-       if not server_status then\r
-               return _M.STATUS_OK\r
-       end\r
-\r
-       local srv_key = str_format("%s:%d", srv.ip, srv.port)\r
-       local srv_status = server_status[srv_key]\r
-\r
-       if srv_status and srv_status.lastmodify + fail_timeout > now() then\r
-               return srv_status.status\r
-       end\r
-\r
-       return _M.STATUS_OK\r
-end\r
-\r
-function _M.set_srv_status(skey, srv, failed)\r
-       local server_status = cluster_status[skey]\r
-       if not server_status then\r
-               server_status = {}\r
-               cluster_status[skey] = server_status\r
-       end\r
-\r
-       local time_now = now()\r
-       local srv_key = str_format("%s:%d", srv.ip, srv.port)\r
-       local srv_status = server_status[srv_key]\r
-       if not srv_status then  -- first set\r
-               srv_status = {\r
-                       status = _M.STATUS_OK,\r
-                       failed_count = 0,\r
-                       lastmodify = time_now\r
-               }\r
-               server_status[srv_key] = srv_status\r
-       elseif srv_status.lastmodify + fail_timeout < time_now then -- srv_status expired\r
-               srv_status.status = _M.STATUS_OK\r
-               srv_status.failed_count = 0\r
-               srv_status.lastmodify = time_now\r
-       end\r
-\r
-       if failed then\r
-               srv_status.failed_count = srv_status.failed_count + 1\r
-               if srv_status.failed_count >= max_fails then\r
-                       srv_status.status = _M.STATUS_ERR\r
-               end\r
-       end\r
-end\r
-\r
-function _M.check_and_reset_srv_status_ifneed(skey,servers)\r
-       local server_status = cluster_status[skey]\r
-       --if disabled servers of the service is empty,do nothing\r
-       if not server_status then \r
-               ngx.log(ngx.DEBUG, "service:",skey,"  server_status is nil")\r
-               return \r
-       end\r
-       local need_reset = true\r
-       for _, srv in ipairs(servers) do\r
-               local srv_key = str_format("%s:%d", srv.ip, srv.port)\r
-           local srv_status = server_status[srv_key]\r
-               if not (srv_status and srv_status.status == _M.STATUS_ERR and srv_status.lastmodify + fail_timeout > now()) then\r
-                       --once find the server is not disabled now, no need to reset the status table. break the loop\r
-                       ngx.log(ngx.DEBUG, "service:",skey," donot need reset,break the loop")\r
-                   need_reset = false\r
-                       break\r
-           end\r
-    end\r
-       if need_reset then\r
-               ngx.log(ngx.DEBUG, "service:",skey," need reset")\r
-               cluster_status[skey] = {}\r
-       end\r
-end\r
-\r
-return _M
\ No newline at end of file
index 0a1b8e8..739b57b 100644 (file)
@@ -1,6 +1,6 @@
 --[[\r
 \r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+    Copyright (C) 2017 ZTE, Inc. and others. All rights reserved. (ZTE)\r
 \r
     Licensed under the Apache License, Version 2.0 (the "License");\r
     you may not use this file except in compliance with the License.\r
index 5ad9c78..1c73495 100644 (file)
@@ -1,6 +1,6 @@
 --[[
 
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
+    Copyright (C) 2017 ZTE, Inc. and others. All rights reserved. (ZTE)
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
index bc84ebc..d02b621 100644 (file)
@@ -1,6 +1,6 @@
 --[[
 
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
+    Copyright (C) 2017 ZTE, Inc. and others. All rights reserved. (ZTE)
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
index f469aa0..4c58349 100644 (file)
@@ -1,6 +1,6 @@
 --[[
 
-    Copyright (C) 201-2018 ZTE, Inc. and others. All rights reserved. (ZTE)
+    Copyright (C) 2017-2018 ZTE, Inc. and others. All rights reserved. (ZTE)
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
index 539053a..9e6fa10 100644 (file)
@@ -1,6 +1,6 @@
 --[[
 
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
+    Copyright (C) 2017 ZTE, Inc. and others. All rights reserved. (ZTE)
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/rewrite/commonrewrite.lua b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/rewrite/commonrewrite.lua
deleted file mode 100644 (file)
index 6bea893..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
---[[\r
-\r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
-\r
-    Licensed under the Apache License, Version 2.0 (the "License");\r
-    you may not use this file except in compliance with the License.\r
-    You may obtain a copy of the License at\r
-\r
-            http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-    Unless required by applicable law or agreed to in writing, software\r
-    distributed under the License is distributed on an "AS IS" BASIS,\r
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-    See the License for the specific language governing permissions and\r
-    limitations under the License.\r
-\r
---]]\r
-\r
-local dbclient  =  require('dao.db_access')\r
-local tbl_util  =  require('lib.utils.table_util')\r
-local svc_util  =  require('lib.utils.svc_util')\r
-local log_util  =  require('lib.utils.log_util')\r
-local error_handler  =  require('lib.utils.error_handler')\r
-\r
-local tbl_concat = table.concat\r
-local tbl_isempty = tbl_util.isempty\r
-local svc_isactive = svc_util.isactive\r
-local svc_get_url = svc_util.get_url\r
-local svc_get_backend_protocol = svc_util.get_backend_protocol\r
-local svc_use_own_upstream = svc_util.use_own_upstream\r
-local svc_get_key_prefix = svc_util.get_key_prefix\r
-local svc_is_api_related_types = svc_util.is_api_related_types\r
-local error_svc_not_found = error_handler.svc_not_found\r
-local error_upstream_not_found = error_handler.upstream_not_found\r
-\r
-local str_sub = string.sub\r
-local str_len = string.len\r
-local str_low = string.lower\r
-local ngx_var = ngx.var\r
-local ngx_ctx = ngx.ctx\r
-local log = log_util.log\r
-\r
----------------------------------------------------------------\r
---preCheck:\r
---     determine whether it is websocket request \r
---     and do internal redirect\r
----------------------------------------------------------------\r
-local http_upgrade = ngx_var.http_upgrade\r
-if(ngx_var.websocket_internal_redirect == "on") and http_upgrade and str_low(http_upgrade) == "websocket" then\r
-       --ngx.log(ngx.ERR, "Websocket request and redirect to @commonwebsocket")\r
-       return ngx.exec("@commonwebsocket");\r
-end\r
-\r
----------------------------------------------------------------\r
---step0:Preparation\r
---      svc_info_key\r
---      svc_server_keypattern\r
----------------------------------------------------------------\r
-local svc_name = ngx_var.svc_name\r
-local req_res  = ngx_var.req_res\r
-local svc_type = ngx_var.svc_type\r
-\r
-local key_prefix = svc_get_key_prefix()\r
-\r
-local svc_key = ""\r
-if(svc_is_api_related_types(svc_type)) then\r
-       -- process version info first\r
-       local version1 = ngx_var.svc_version1\r
-       local version2 = ngx_var.svc_version2\r
-       local version = ""\r
-       -- check version info appearing befor or after\r
-       if(not version2) then version2 = "" end --convert nil to empty sting avoiding throw error\r
-       if(not version1 or version1 == "") then\r
-               version = version2\r
-       else\r
-               version = version1\r
-               req_res = version2..req_res\r
-       end\r
-       -- remove the slash in front of the version (e.g. /V1.0)\r
-       local svc_version=str_sub(version,2,str_len(version))\r
-       svc_key = tbl_concat({key_prefix,"api",svc_name,svc_version},":")\r
-else\r
-       svc_key = tbl_concat({key_prefix,"iui",svc_name},":")\r
-end\r
-\r
----------------------------------------------------------------\r
---step1:query the service info from share memory or back db\r
---      svcinfo: the requested service information\r
----------------------------------------------------------------\r
-local svcinfo = dbclient.load_serviceinfo(svc_key)\r
-if tbl_isempty(svcinfo) then\r
-       error_svc_not_found("No route found for this request!","common not match. key--"..svc_key)\r
-end\r
-if not svc_isactive(svcinfo) then\r
-       error_svc_not_found("Service is disabled!","common not match. key--"..svc_key)\r
-end\r
-\r
-local svc_url = svc_get_url(svcinfo,svc_type)\r
-\r
----------------------------------------------------------------\r
---step2:rewrite the request uri using the svcinfo\r
----------------------------------------------------------------\r
-local rewrited_uri = svc_url..req_res\r
---special handling: avoid throws internal error when it is empty\r
---if (rewrited_uri == "") then rewrited_uri = "/" end\r
-if (rewrited_uri == "") then return ngx.redirect(ngx.var.uri.."/") end \r
-ngx.req.set_uri(rewrited_uri)\r
-\r
-log("matched",svc_name)\r
---log("rewrited_uri",rewrited_uri)\r
----------------------------------------------------------------\r
---step2.1:store the svcinfo in the context, plugins may use it\r
----------------------------------------------------------------\r
-ngx_ctx.svcinfo = svcinfo\r
-\r
----------------------------------------------------------------\r
---step3:process the proxy upstream part\r
--- con1-using consul template:set the upstream name\r
--- con2-using msb balancer:query the server list and store in the ctx\r
----------------------------------------------------------------\r
---set the http_protocol used by proxy_pass directive\r
-ngx_var.http_protocol = svc_get_backend_protocol(svcinfo)\r
-\r
-if svc_use_own_upstream(svcinfo) then\r
-       local consul_servicename = svcinfo.spec["consulServiceName"]\r
-       if not consul_servicename or consul_servicename == "" then\r
-               error_upstream_not_found()\r
-       end\r
-       ngx_var.backend = consul_servicename\r
-       ngx.ctx.use_ownupstream = true\r
-else\r
-       local backservers = svcinfo.spec.nodes\r
-       if tbl_isempty(backservers) then\r
-               error_svc_not_found("No active backend server found!"," key--"..svc_key)\r
-       end\r
-       ngx_ctx.backservers = backservers\r
-       ngx_ctx.svc_key = svc_key\r
-end
\ No newline at end of file
diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/rewrite/customrewrite.lua b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/rewrite/customrewrite.lua
deleted file mode 100644 (file)
index 89a829d..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
---[[\r
-\r
-    Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
-\r
-    Licensed under the Apache License, Version 2.0 (the "License");\r
-    you may not use this file except in compliance with the License.\r
-    You may obtain a copy of the License at\r
-\r
-            http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-    Unless required by applicable law or agreed to in writing, software\r
-    distributed under the License is distributed on an "AS IS" BASIS,\r
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-    See the License for the specific language governing permissions and\r
-    limitations under the License.\r
-\r
---]]\r
-\r
-local msbConf   =  require('conf.msbinit')\r
-local dbclient  =  require('dao.db_access')\r
-local tbl_util  =  require('lib.utils.table_util')\r
-local svc_util  =  require('lib.utils.svc_util')\r
-local log_util  =  require('lib.utils.log_util')\r
-local error_handler  =  require('lib.utils.error_handler')\r
-\r
-local tbl_concat = table.concat\r
-local tbl_isempty = tbl_util.isempty\r
-local svc_isactive = svc_util.isactive\r
-local svc_get_url = svc_util.get_url\r
-local svc_get_backend_protocol = svc_util.get_backend_protocol\r
-local svc_use_own_upstream = svc_util.use_own_upstream\r
-local svc_get_key_prefix = svc_util.get_key_prefix\r
-local str_low = string.lower\r
-local ngx_var = ngx.var\r
-local ngx_ctx = ngx.ctx\r
-local log = log_util.log\r
-local error_svc_not_found = error_handler.svc_not_found\r
-local error_upstream_not_found = error_handler.upstream_not_found\r
-\r
-local enablerefercheck = msbConf.systemConf.enablerefercheck\r
-local useconsultemplate = msbConf.systemConf.useconsultemplate\r
-\r
----------------------------------------------------------------\r
---preCheck:\r
---     determine whether it is websocket request \r
---     and do internal redirect\r
----------------------------------------------------------------\r
-if ngx.var.uri == "/" then\r
-       local m, err = ngx.re.match(ngx.var.host, "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$","o")\r
-       if m then\r
-               return ngx.exec("@defaultpage")\r
-       end\r
-end\r
-\r
-local http_upgrade = ngx_var.http_upgrade\r
-if(ngx_var.websocket_internal_redirect == "on") and http_upgrade and str_low(http_upgrade)== "websocket" then\r
-       --ngx.log(ngx.ERR, "Websocket request and redirect to @customwebsocket")\r
-       return ngx.exec("@customwebsocket")\r
-end\r
-\r
----------------------------------------------------------------\r
---step0:Preparation\r
---      svcnames:service names registered under this port\r
----------------------------------------------------------------\r
-local req_res  = ngx_var.uri\r
-local svc_type = ngx_var.svc_type\r
-local key_prefix = svc_get_key_prefix()\r
-\r
-local custom_svc_keypattern = tbl_concat({key_prefix,"custom","*"},":")\r
-\r
-local get_svckey_custom = function(svcname)\r
-       return tbl_concat({key_prefix,"custom",svcname},":")\r
-end\r
-\r
-local svcnames,err = dbclient.load_customsvcnames(custom_svc_keypattern)\r
-if not svcnames then\r
-       error_svc_not_found("Failed to load the route table!","keypattern--"..custom_svc_keypattern)\r
-end\r
-\r
----------------------------------------------------------------\r
---step1:run the match process(check whether the request \r
---      match the name in the svcnames one by one) \r
---      and return the matched serice info\r
----------------------------------------------------------------\r
-local matchedsvcname\r
-local svcinfo\r
-local svc_key = ""\r
---add by wangyg:20160418 special handler for refer\r
-local matched_usingrefer = false\r
---end of add by wangyg:20160418 special handler for refer\r
-for _, svcname in ipairs(svcnames) do\r
-       if (svcname == "/") then\r
-               svc_key = get_svckey_custom(svcname)\r
-               local svc_info,err = dbclient.load_serviceinfo(svc_key)\r
-               if svc_info and svc_isactive(svc_info)then\r
-                       matchedsvcname = svcname\r
-                       svcinfo = svc_info\r
-                       break\r
-               end\r
-       end\r
-       local from, to, err = ngx.re.find(req_res, "^"..svcname.."(/(.*))?$", "jo")\r
-       --check whether svcname is the prefix of the req uri\r
-       if from then\r
-               svc_key = get_svckey_custom(svcname)\r
-               local svc_info,err = dbclient.load_serviceinfo(svc_key)\r
-               if svc_info and svc_isactive(svc_info) then \r
-                       matchedsvcname = svcname\r
-                       svcinfo = svc_info\r
-                       break\r
-               end\r
-       else\r
-               --do nothing\r
-       end\r
-end\r
----------------------------------------------------------------\r
---step1.1:additional process,test against the refer \r
---        similar to step1\r
----------------------------------------------------------------\r
---add by wangyg:20160418 special handler for refer\r
-if not matchedsvcname and enablerefercheck then \r
-       local refer =  ngx_var.http_referer\r
-       if(refer and refer~="") then\r
-               for _, svcname in ipairs(svcnames) do\r
-                       local urlreg ="^(https://|http://|)(([1-9]|([1-9]\\d)|(1\\d\\d)|(2([0-4]\\d|5[0-5])))\\.)(([0-9]|([1-9]\\d)|(1\\d\\d)|(2([0-4]\\d|5[0-5])))\\.){2}([1-9]|([1-9]\\d)|(1\\d\\d)|(2([0-4]\\d|5[0-5])))(:\\d{1,5})?"..svcname.."(/(.*))?$";\r
-                       local from, to, err = ngx.re.find(refer, urlreg, "jo")\r
-                       ----check whether svcname is the prefix of the req refer\r
-                       if from then\r
-                               svc_key = get_svckey_custom(svcname)\r
-                               local svc_info,err = dbclient.load_serviceinfo(svc_key)\r
-                               if svc_info and svc_isactive(svc_info) then \r
-                                       matchedsvcname = svcname\r
-                                       svcinfo = svc_info\r
-                                       matched_usingrefer = true\r
-                                       break\r
-                               end\r
-                       end\r
-               end\r
-       end\r
-end\r
---end of add by wangyg:20160418 special handler for refer\r
-\r
-if not matchedsvcname or tbl_isempty(svcinfo) then\r
-       error_svc_not_found("No route found for this request!","custom not match")\r
-end\r
-\r
-local svc_url = svc_get_url(svcinfo,svc_type)\r
-\r
----------------------------------------------------------------\r
---step2:rewrite the request uri using the svcinfo\r
----------------------------------------------------------------\r
-local rewrited_uri =""\r
-if (matchedsvcname == "/") then\r
-       --special handling: if "/" matched, contact directly\r
-       rewrited_uri = svc_url..req_res\r
-else\r
-       --rewrited_uri = ngx.re.sub(req_res, "^"..matchedsvcname.."(.*)", svc_url.."$1", "o")\r
-       local newuri,n,err = ngx.re.sub(req_res, "^"..matchedsvcname.."(/.*)?", svc_url.."$1", "o")\r
-       --add by wangyg:20160418 special handler for refer\r
-       if(n==0 and matched_usingrefer) then newuri = svc_url..req_res end --special handling if matched using refer\r
-       --end of add by wangyg:20160418 special handler for refer\r
-       rewrited_uri = newuri\r
-end\r
---if (rewrited_uri == "") then rewrited_uri = "/" end --avoid throws internal error when it is empty\r
-if (rewrited_uri == "") then return ngx.redirect(ngx.var.uri.."/") end \r
-ngx.req.set_uri(rewrited_uri)\r
-\r
---set the matched service info,used in the proxy_redirect directive \r
-ngx_var.svc_name = matchedsvcname\r
-ngx_var.svc_url =  svc_url\r
-\r
---log the route info\r
-log("matched",matchedsvcname)\r
-if(matched_usingrefer) then log("matched_usingrefer",true) end \r
---log("rewrited_uri",rewrited_uri)\r
-\r
----------------------------------------------------------------\r
---step2.1:store the svcinfo in the context, plugins may use it\r
----------------------------------------------------------------\r
-ngx_ctx.svcinfo = svcinfo\r
-\r
----------------------------------------------------------------\r
---step3:process the proxy upstream part\r
--- con1-using consul template:set the upstream name\r
--- con2-using msb balancer:query the backserver list and store in the ctx\r
----------------------------------------------------------------\r
---set the http_protocol used by proxy_pass directive\r
-ngx_var.http_protocol = svc_get_backend_protocol(svcinfo)\r
-\r
-if svc_use_own_upstream(svcinfo) then\r
-       local consul_servicename = svcinfo.spec["consulServiceName"]\r
-       if not consul_servicename or consul_servicename == "" then\r
-               error_upstream_not_found()\r
-       end\r
-       ngx_var.backend = consul_servicename\r
-       ngx.ctx.use_ownupstream = true\r
-else\r
-       local backservers = svcinfo.spec.nodes\r
-       if tbl_isempty(backservers) then\r
-               error_svc_not_found("No active backend server found!","key--"..svc_key)\r
-       end\r
-       ngx_ctx.backservers = backservers\r
-       ngx_ctx.svc_key = svc_key\r
-end
\ No newline at end of file
diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/msb-enabled/location-ext/defaultpage.conf b/openresty-ext/src/assembly/resources/openresty/nginx/msb-enabled/location-ext/defaultpage.conf
deleted file mode 100644 (file)
index edd9ed9..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-location @defaultpage {
-       content_by_lua_block{
-               local error_page_head = '<html><head><title>502 Bad Gateway</title></head><body bgcolor="white"><center><h1>502 Bad Gateway</h1></center><center>error message:'
-               local error_page_foot = '</center><hr><center>nginx</center></body></html>'
-               ngx.status = ngx.HTTP_BAD_GATEWAY
-               ngx.print(error_page_head.."default homepage undefined"..error_page_foot)
-               return ngx.exit(ngx.status)
-       }
-}
\ No newline at end of file
index 1b64c0d..ed2a393 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
+# Copyright (C) 2017 ZTE, Inc. and others. All rights reserved. (ZTE)
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
index 329dabc..e956aa7 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
+# Copyright (C) 2017 ZTE, Inc. and others. All rights reserved. (ZTE)
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
index 343bff4..a5cbac1 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 #
-# Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
+# Copyright (C) 2017 ZTE, Inc. and others. All rights reserved. (ZTE)
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.