Skip to content

Commit

Permalink
feature: added new API ngx.config.debug to indicate whether this is a…
Browse files Browse the repository at this point in the history
… debug build of nginx.
  • Loading branch information
agentzh committed Sep 1, 2013
1 parent fdec270 commit 9577e5f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config
Expand Up @@ -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 \
Expand Down Expand Up @@ -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"
Expand Down
32 changes: 32 additions & 0 deletions 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");
}
19 changes: 19 additions & 0 deletions 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: */
2 changes: 2 additions & 0 deletions src/ngx_http_lua_util.c
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
33 changes: 33 additions & 0 deletions 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]

0 comments on commit 9577e5f

Please sign in to comment.