diff options
author | 2016-09-20 11:31:05 +0800 | |
---|---|---|
committer | 2016-09-20 11:31:05 +0800 | |
commit | e268131c6c3c868bef106ca8368fd0388b23c4ed (patch) | |
tree | 9b777037d4297081fb9e9dfc68c71f0a3b3449f7 /msb-core/openresty-ext/src/assembly/resources/openresty/lualib/resty/http_headers.lua | |
parent | 6be48e1015bc20005ed31f8b857842a59e1c9dfa (diff) |
1. add the auth lua plugin and the driver lua plugin.
Change-Id: Id446447dbd904092f7dd2d1326d3c51c4876713b
Signed-off-by: zhouruiyu <zhouruiyu@huawei.com>
Diffstat (limited to 'msb-core/openresty-ext/src/assembly/resources/openresty/lualib/resty/http_headers.lua')
-rw-r--r-- | msb-core/openresty-ext/src/assembly/resources/openresty/lualib/resty/http_headers.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/msb-core/openresty-ext/src/assembly/resources/openresty/lualib/resty/http_headers.lua b/msb-core/openresty-ext/src/assembly/resources/openresty/lualib/resty/http_headers.lua new file mode 100644 index 0000000..24b53b5 --- /dev/null +++ b/msb-core/openresty-ext/src/assembly/resources/openresty/lualib/resty/http_headers.lua @@ -0,0 +1,62 @@ +local rawget, rawset, setmetatable = + rawget, rawset, setmetatable + +local str_gsub = string.gsub +local str_lower = string.lower + + +local _M = { + _VERSION = '0.01', +} + + +-- Returns an empty headers table with internalised case normalisation. +-- Supports the same cases as in ngx_lua: +-- +-- headers.content_length +-- headers["content-length"] +-- headers["Content-Length"] +function _M.new(self) + local mt = { + normalised = {}, + } + + + mt.__index = function(t, k) + local k_hyphened = str_gsub(k, "_", "-") + local matched = rawget(t, k) + if matched then + return matched + else + local k_normalised = str_lower(k_hyphened) + return rawget(t, mt.normalised[k_normalised]) + end + end + + + -- First check the normalised table. If there's no match (first time) add an entry for + -- our current case in the normalised table. This is to preserve the human (prettier) case + -- instead of outputting lowercased header names. + -- + -- If there's a match, we're being updated, just with a different case for the key. We use + -- the normalised table to give us the original key, and perorm a rawset(). + mt.__newindex = function(t, k, v) + -- we support underscore syntax, so always hyphenate. + local k_hyphened = str_gsub(k, "_", "-") + + -- lowercase hyphenated is "normalised" + local k_normalised = str_lower(k_hyphened) + + if not mt.normalised[k_normalised] then + mt.normalised[k_normalised] = k_hyphened + rawset(t, k_hyphened, v) + else + rawset(t, mt.normalised[k_normalised], v) + end + end + + return setmetatable({}, mt) +end + + +return _M |