-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: introducing ngx_stub.lua for specs
- Loading branch information
1 parent
2cf80ea
commit 663e130
Showing
4 changed files
with
44 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
local reg = require "rex_pcre" | ||
|
||
_G.ngx = { | ||
time = function() return os.time() end, -- cassandra.lua | ||
re = { | ||
match = reg.match | ||
} | ||
}, | ||
-- Builds a querystring from a table, separated by `&` | ||
-- @param tab The key/value parameters | ||
-- @param key The parent key if the value is multi-dimensional (optional) | ||
-- @return a string representing the built querystring | ||
encode_args = function(tab, key) | ||
local query = {} | ||
local keys = {} | ||
|
||
for k in pairs(tab) do | ||
keys[#keys+1] = k | ||
end | ||
|
||
table.sort(keys) | ||
|
||
for _, name in ipairs(keys) do | ||
local value = tab[name] | ||
if key then | ||
name = string.format("%s[%s]", tostring(key), tostring(name)) | ||
end | ||
if type(value) == "table" then | ||
query[#query+1] = build_query(value, name) | ||
else | ||
value = tostring(value) | ||
if value ~= "" then | ||
query[#query+1] = string.format("%s=%s", name, value) | ||
else | ||
query[#query+1] = name | ||
end | ||
end | ||
end | ||
|
||
return table.concat(query, "&") | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters