Skip to content
This repository was archived by the owner on May 9, 2022. It is now read-only.

Commit 195baff

Browse files
committed
feature: implemented the set_by_lua_block directive.
1 parent effd1d1 commit 195baff

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

src/ngx_http_lua_directive.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,25 @@ ngx_http_lua_package_path(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
205205

206206

207207
#if defined(NDK) && NDK
208+
char *
209+
ngx_http_lua_set_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd,
210+
void *conf)
211+
{
212+
char *rv;
213+
ngx_conf_t save;
214+
215+
save = *cf;
216+
cf->handler = ngx_http_lua_set_by_lua;
217+
cf->handler_conf = conf;
218+
219+
rv = ngx_http_lua_conf_lua_block_parse(cf, cmd);
220+
221+
*cf = save;
222+
223+
return rv;
224+
}
225+
226+
208227
char *
209228
ngx_http_lua_set_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
210229
{
@@ -1356,7 +1375,9 @@ ngx_http_lua_conf_lua_block_parse(ngx_conf_t *cf, ngx_command_t *cmd)
13561375

13571376
dd("saved nelts: %d", (int) saved->nelts);
13581377
dd("temp nelts: %d", (int) cf->args->nelts);
1378+
#if 0
13591379
ngx_http_lua_assert(saved->nelts == 1);
1380+
#endif
13601381

13611382
dst = ngx_array_push(saved);
13621383
if (dst == NULL) {

src/ngx_http_lua_directive.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ char *ngx_http_lua_code_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
5353

5454
#if defined(NDK) && NDK
5555

56+
char *ngx_http_lua_set_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd,
57+
void *conf);
5658
char *ngx_http_lua_set_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
5759
char *ngx_http_lua_set_by_lua_file(ngx_conf_t *cf, ngx_command_t *cmd,
5860
void *conf);

src/ngx_http_lua_module.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ static ngx_command_t ngx_http_lua_cmds[] = {
192192
(void *) ngx_http_lua_init_worker_by_file },
193193

194194
#if defined(NDK) && NDK
195+
/* set_by_lua $res { inline Lua code } [$arg1 [$arg2 [...]]] */
196+
{ ngx_string("set_by_lua_block"),
197+
NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
198+
|NGX_CONF_1MORE|NGX_CONF_BLOCK,
199+
ngx_http_lua_set_by_lua_block,
200+
NGX_HTTP_LOC_CONF_OFFSET,
201+
0,
202+
(void *) ngx_http_lua_filter_set_by_lua_inline },
203+
195204
/* set_by_lua $res <inline script> [$arg1 [$arg2 [...]]] */
196205
{ ngx_string("set_by_lua"),
197206
NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF

t/132-lua-blocks.t

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,33 @@ GET /t
381381
--- error_log eval
382382
qr{\[emerg\] .*? unexpected lua closing long-bracket in .*?/nginx\.conf:41}
383383
--- must_die
384+
385+
386+
387+
=== TEST 15: simple set_by_lua_block (integer)
388+
--- config
389+
location /lua {
390+
set_by_lua_block $res { return 1+1 }
391+
echo $res;
392+
}
393+
--- request
394+
GET /lua
395+
--- response_body
396+
2
397+
--- no_error_log
398+
[error]
399+
400+
401+
402+
=== TEST 16: set_by_lua_block with arguments
403+
--- config
404+
location /lua {
405+
set_by_lua $res "return ngx.arg[1] + ngx.arg[2]" $arg_a $arg_b;
406+
echo $res;
407+
}
408+
--- request
409+
GET /lua?a=1&b=2
410+
--- response_body
411+
3
412+
--- no_error_log
413+
[error]

0 commit comments

Comments
 (0)