Permalink
Browse files

avoid using globals to define rules

  • Loading branch information...
fffonion committed Feb 6, 2018
1 parent a612e51 commit 1a70d9c15eb9814328e78a411d9eec7a09e926ca
Showing with 10 additions and 8 deletions.
  1. +3 −2 README.md
  2. +7 −6 lib/resty/sniproxy.lua
@@ -36,8 +36,9 @@ Synopsis
```
stream {
init_worker_by_lua_block {
sni_rules = {
init_by_lua_block {
local sni = require("resty.sniproxy")
sni.rules = {
{"www.google.com", "www.google.com", 443},
{"www.facebook.com", "9.8.7.6", 443},
{"api.twitter.com", "1.2.3.4"},
@@ -23,8 +23,9 @@ if not ok or type(new_tab) ~= "function" then
end
local _M = new_tab(0, 20)
_M._VERSION = '0.01'
local _M = new_tab(0, 4)
_M._VERSION = '0.02'
_M.rules = {}
local mt = { __index = _M }
@@ -264,8 +265,8 @@ local function _dwn(self)
end
function _M.run(self)
if sni_rules == nil then
ngx.log(ngx.ERR, "sni_rules not defined")
if _M.rules == nil then
ngx.log(ngx.ERR, "sni rules not defined")
return
end
while true do
@@ -279,7 +280,7 @@ function _M.run(self)
if self.server_name == nil then -- no sni extension, only match default rule
self.server_name = "."
end
for _, v in pairs(sni_rules) do
for _, v in pairs(_M.rules) do
local m, e = ngx.re.match(self.server_name, v[1], "jo")
if m then
upstream = v[2] or self.server_name
@@ -313,4 +314,4 @@ function _M.run(self)
end
return _M
return _M

0 comments on commit 1a70d9c

Please sign in to comment.