-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opimize: used lua table to cache the ngx variable.
- Loading branch information
Showing
8 changed files
with
65 additions
and
53 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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
local new_tab = require("table.new") | ||
local ngx_var = ngx.var | ||
|
||
|
||
local _M = {version = 0.1} | ||
|
||
|
||
do | ||
local var_methods = { | ||
["method"] = ngx.req.get_method | ||
} | ||
|
||
local mt = { | ||
__index = function(t, name) | ||
local val | ||
local method = var_methods[name] | ||
if method then | ||
val = method() | ||
|
||
else | ||
val = ngx_var[name] | ||
end | ||
|
||
if val then | ||
t[name] = val | ||
end | ||
|
||
return val | ||
end | ||
} | ||
|
||
function _M.set_vars_meta(ctx) | ||
ctx.var = new_tab(0, 32) | ||
setmetatable(ctx.var, mt) | ||
end | ||
|
||
end -- do | ||
|
||
|
||
return _M |
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
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
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