Skip to content

Commit 9577e5f

Browse files
committed
feature: added new API ngx.config.debug to indicate whether this is a debug build of nginx.
1 parent fdec270 commit 9577e5f

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
222222
$ngx_addon_dir/src/ngx_http_lua_phase.c \
223223
$ngx_addon_dir/src/ngx_http_lua_uthread.c \
224224
$ngx_addon_dir/src/ngx_http_lua_timer.c \
225+
$ngx_addon_dir/src/ngx_http_lua_config.c \
225226
"
226227

227228
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
@@ -272,6 +273,7 @@ NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
272273
$ngx_addon_dir/src/ngx_http_lua_probe.h \
273274
$ngx_addon_dir/src/ngx_http_lua_uthread.h \
274275
$ngx_addon_dir/src/ngx_http_lua_timer.h \
276+
$ngx_addon_dir/src/ngx_http_lua_config.h \
275277
"
276278

277279
CFLAGS="$CFLAGS -DNDK_SET_VAR"

src/ngx_http_lua_config.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
/*
3+
* Copyright (C) Yichun Zhang (agentzh)
4+
*/
5+
6+
7+
#ifndef DDEBUG
8+
#define DDEBUG 0
9+
#endif
10+
#include "ddebug.h"
11+
12+
13+
#include "ngx_http_lua_config.h"
14+
15+
16+
void
17+
ngx_http_lua_inject_config_api(lua_State *L)
18+
{
19+
/* ngx.config */
20+
21+
lua_newtable(L); /* .config */
22+
23+
#if (NGX_DEBUG)
24+
lua_pushboolean(L, 1);
25+
#else
26+
lua_pushboolean(L, 0);
27+
#endif
28+
29+
lua_setfield(L, -2, "debug");
30+
31+
lua_setfield(L, -2, "config");
32+
}

src/ngx_http_lua_config.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
/*
3+
* Copyright (C) Yichun Zhang (agentzh)
4+
*/
5+
6+
7+
#ifndef _NGX_HTTP_LUA_CONFIG_H_INCLUDED_
8+
#define _NGX_HTTP_LUA_CONFIG_H_INCLUDED_
9+
10+
11+
#include "ngx_http_lua_common.h"
12+
13+
14+
void ngx_http_lua_inject_config_api(lua_State *L);
15+
16+
17+
#endif /* _NGX_HTTP_LUA_CONFIG_H_INCLUDED_ */
18+
19+
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ngx_http_lua_util.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "ngx_http_lua_uthread.h"
4747
#include "ngx_http_lua_contentby.h"
4848
#include "ngx_http_lua_timer.h"
49+
#include "ngx_http_lua_config.h"
4950

5051

5152
#if 1
@@ -770,6 +771,7 @@ ngx_http_lua_inject_ngx_api(ngx_conf_t *cf, lua_State *L)
770771
ngx_http_lua_inject_socket_udp_api(cf->log, L);
771772
ngx_http_lua_inject_uthread_api(cf->log, L);
772773
ngx_http_lua_inject_timer_api(L);
774+
ngx_http_lua_inject_config_api(L);
773775

774776
ngx_http_lua_inject_misc_api(L);
775777

t/114-config.t

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# vim:set ft= ts=4 sw=4 et fdm=marker:
2+
use lib 'lib';
3+
use t::TestNginxLua;
4+
5+
#worker_connections(1014);
6+
#master_on();
7+
#workers(2);
8+
#log_level('warn');
9+
10+
repeat_each(2);
11+
12+
plan tests => repeat_each() * (blocks() * 3);
13+
14+
#no_diff();
15+
#no_long_string();
16+
run_tests();
17+
18+
__DATA__
19+
20+
=== TEST 1: ngx.config.debug
21+
--- config
22+
location /t {
23+
content_by_lua '
24+
ngx.say("debug: ", ngx.config.debug)
25+
';
26+
}
27+
--- request
28+
GET /t
29+
--- response_body_like chop
30+
^debug: (?:true|false)$
31+
--- no_error_log
32+
[error]
33+

0 commit comments

Comments
 (0)