diff --git a/config b/config index a7e13bc4cd..84f717218f 100644 --- a/config +++ b/config @@ -222,6 +222,7 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS \ $ngx_addon_dir/src/ngx_http_lua_phase.c \ $ngx_addon_dir/src/ngx_http_lua_uthread.c \ $ngx_addon_dir/src/ngx_http_lua_timer.c \ + $ngx_addon_dir/src/ngx_http_lua_config.c \ " NGX_ADDON_DEPS="$NGX_ADDON_DEPS \ @@ -272,6 +273,7 @@ NGX_ADDON_DEPS="$NGX_ADDON_DEPS \ $ngx_addon_dir/src/ngx_http_lua_probe.h \ $ngx_addon_dir/src/ngx_http_lua_uthread.h \ $ngx_addon_dir/src/ngx_http_lua_timer.h \ + $ngx_addon_dir/src/ngx_http_lua_config.h \ " CFLAGS="$CFLAGS -DNDK_SET_VAR" diff --git a/src/ngx_http_lua_config.c b/src/ngx_http_lua_config.c new file mode 100644 index 0000000000..38e20b960c --- /dev/null +++ b/src/ngx_http_lua_config.c @@ -0,0 +1,32 @@ + +/* + * Copyright (C) Yichun Zhang (agentzh) + */ + + +#ifndef DDEBUG +#define DDEBUG 0 +#endif +#include "ddebug.h" + + +#include "ngx_http_lua_config.h" + + +void +ngx_http_lua_inject_config_api(lua_State *L) +{ + /* ngx.config */ + + lua_newtable(L); /* .config */ + +#if (NGX_DEBUG) + lua_pushboolean(L, 1); +#else + lua_pushboolean(L, 0); +#endif + + lua_setfield(L, -2, "debug"); + + lua_setfield(L, -2, "config"); +} diff --git a/src/ngx_http_lua_config.h b/src/ngx_http_lua_config.h new file mode 100644 index 0000000000..9f85f31b3c --- /dev/null +++ b/src/ngx_http_lua_config.h @@ -0,0 +1,19 @@ + +/* + * Copyright (C) Yichun Zhang (agentzh) + */ + + +#ifndef _NGX_HTTP_LUA_CONFIG_H_INCLUDED_ +#define _NGX_HTTP_LUA_CONFIG_H_INCLUDED_ + + +#include "ngx_http_lua_common.h" + + +void ngx_http_lua_inject_config_api(lua_State *L); + + +#endif /* _NGX_HTTP_LUA_CONFIG_H_INCLUDED_ */ + +/* vi:set ft=c ts=4 sw=4 et fdm=marker: */ diff --git a/src/ngx_http_lua_util.c b/src/ngx_http_lua_util.c index a90825fb9f..33ac849ce1 100644 --- a/src/ngx_http_lua_util.c +++ b/src/ngx_http_lua_util.c @@ -46,6 +46,7 @@ #include "ngx_http_lua_uthread.h" #include "ngx_http_lua_contentby.h" #include "ngx_http_lua_timer.h" +#include "ngx_http_lua_config.h" #if 1 @@ -770,6 +771,7 @@ ngx_http_lua_inject_ngx_api(ngx_conf_t *cf, lua_State *L) ngx_http_lua_inject_socket_udp_api(cf->log, L); ngx_http_lua_inject_uthread_api(cf->log, L); ngx_http_lua_inject_timer_api(L); + ngx_http_lua_inject_config_api(L); ngx_http_lua_inject_misc_api(L); diff --git a/t/114-config.t b/t/114-config.t new file mode 100644 index 0000000000..3a3f9d27c5 --- /dev/null +++ b/t/114-config.t @@ -0,0 +1,33 @@ +# vim:set ft= ts=4 sw=4 et fdm=marker: +use lib 'lib'; +use t::TestNginxLua; + +#worker_connections(1014); +#master_on(); +#workers(2); +#log_level('warn'); + +repeat_each(2); + +plan tests => repeat_each() * (blocks() * 3); + +#no_diff(); +#no_long_string(); +run_tests(); + +__DATA__ + +=== TEST 1: ngx.config.debug +--- config + location /t { + content_by_lua ' + ngx.say("debug: ", ngx.config.debug) + '; + } +--- request +GET /t +--- response_body_like chop +^debug: (?:true|false)$ +--- no_error_log +[error] +