bugfix: ngx.get_phase() does not work in the context of init_worker_by_lua*.

This commit is contained in:
Yichun Zhang (agentzh) 2014-10-28 21:38:06 -07:00
Родитель 5eb3f8c6f8
Коммит 3c1918df8d
4 изменённых файлов: 29 добавлений и 4 удалений

Просмотреть файл

@ -6220,12 +6220,14 @@ ngx.get_phase
-------------
**syntax:** *str = ngx.get_phase()*
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
**context:** *init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
Retrieves the current running phase name. Possible return values are
* `init`
for the context of [init_by_lua](#init_by_lua) or [init_by_lua_file](#init_by_lua_file).
* `init_worker`
for the context of [init_worker_by_lua](#init_worker_by_lua) or [init_worker_by_lua_file](#init_worker_by_lua_file).
* `set`
for the context of [set_by_lua](#set_by_lua) or [set_by_lua_file](#set_by_lua_file).
* `rewrite`

Просмотреть файл

@ -5228,12 +5228,14 @@ This feature was first introduced in the <code>v0.5.0rc1</code> release.
== ngx.get_phase ==
'''syntax:''' ''str = ngx.get_phase()''
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*''
'''context:''' ''init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*''
Retrieves the current running phase name. Possible return values are
* <code>init</code>
: for the context of [[#init_by_lua|init_by_lua]] or [[#init_by_lua_file|init_by_lua_file]].
* <code>init_worker</code>
: for the context of [[#init_worker_by_lua|init_worker_by_lua]] or [[#init_worker_by_lua_file|init_worker_by_lua_file]].
* <code>set</code>
: for the context of [[#set_by_lua|set_by_lua]] or [[#set_by_lua_file|set_by_lua_file]].
* <code>rewrite</code>

Просмотреть файл

@ -40,6 +40,10 @@ ngx_http_lua_ngx_get_phase(lua_State *L)
}
switch (ctx->context) {
case NGX_HTTP_LUA_CONTEXT_INIT_WORKER:
lua_pushliteral(L, "init_worker");
break;
case NGX_HTTP_LUA_CONTEXT_SET:
lua_pushliteral(L, "set");
break;

Просмотреть файл

@ -7,9 +7,8 @@ use Test::Nginx::Socket::Lua;
log_level('warn');
repeat_each(2);
#repeat_each(1);
plan tests => repeat_each() * (blocks() * 2);
plan tests => repeat_each() * (blocks() * 2 + 1);
#no_diff();
#no_long_string();
@ -160,3 +159,21 @@ GET /lua
--- error_log
current phase: timer
=== TEST 10: get_phase in init_worker_by_lua
--- http_config
init_worker_by_lua 'phase = ngx.get_phase()';
--- config
location /lua {
content_by_lua '
ngx.say(phase)
';
}
--- request
GET /lua
--- response_body
init_worker
--- no_error_log
[error]