@@ -32,10 +32,6 @@ static void ngx_http_lua_body_filter_by_lua_env(lua_State *L,
32
32
static ngx_http_output_body_filter_pt ngx_http_next_body_filter ;
33
33
34
34
35
- /* key for the ngx_chain_t *in pointer in the Lua thread */
36
- #define ngx_http_lua_chain_key "__ngx_cl"
37
-
38
-
39
35
/**
40
36
* Set environment table for the given code closure.
41
37
*
@@ -51,12 +47,14 @@ static void
51
47
ngx_http_lua_body_filter_by_lua_env (lua_State * L , ngx_http_request_t * r ,
52
48
ngx_chain_t * in )
53
49
{
54
- /* set nginx request pointer to current lua thread's globals table */
50
+ ngx_http_lua_main_conf_t * lmcf ;
51
+
55
52
ngx_http_lua_set_req (L , r );
56
53
57
- lua_pushlightuserdata ( L , in );
58
- lua_setglobal ( L , ngx_http_lua_chain_key ) ;
54
+ lmcf = ngx_http_get_module_main_conf ( r , ngx_http_lua_module );
55
+ lmcf -> body_filter_chain = in ;
59
56
57
+ #ifndef OPENRESTY_LUAJIT
60
58
/**
61
59
* we want to create empty environment for current script
62
60
*
@@ -79,6 +77,7 @@ ngx_http_lua_body_filter_by_lua_env(lua_State *L, ngx_http_request_t *r,
79
77
/* }}} */
80
78
81
79
lua_setfenv (L , -2 ); /* set new running env for the code closure */
80
+ #endif /* OPENRESTY_LUAJIT */
82
81
}
83
82
84
83
@@ -236,8 +235,8 @@ ngx_http_lua_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
236
235
ngx_int_t rc ;
237
236
uint16_t old_context ;
238
237
ngx_http_cleanup_t * cln ;
239
- lua_State * L ;
240
238
ngx_chain_t * out ;
239
+ ngx_http_lua_main_conf_t * lmcf ;
241
240
242
241
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
243
242
"lua body filter for user lua code, uri \"%V\"" , & r -> uri );
@@ -299,11 +298,8 @@ ngx_http_lua_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
299
298
return NGX_ERROR ;
300
299
}
301
300
302
- L = ngx_http_lua_get_lua_vm (r , ctx );
303
-
304
- lua_getglobal (L , ngx_http_lua_chain_key );
305
- out = lua_touserdata (L , -1 );
306
- lua_pop (L , 1 );
301
+ lmcf = ngx_http_get_module_main_conf (r , ngx_http_lua_module );
302
+ out = lmcf -> body_filter_chain ;
307
303
308
304
if (in == out ) {
309
305
return ngx_http_next_body_filter (r , in );
@@ -345,7 +341,7 @@ ngx_http_lua_body_filter_init(void)
345
341
346
342
347
343
int
348
- ngx_http_lua_body_filter_param_get (lua_State * L )
344
+ ngx_http_lua_body_filter_param_get (lua_State * L , ngx_http_request_t * r )
349
345
{
350
346
u_char * data , * p ;
351
347
size_t size ;
@@ -354,6 +350,8 @@ ngx_http_lua_body_filter_param_get(lua_State *L)
354
350
int idx ;
355
351
ngx_chain_t * in ;
356
352
353
+ ngx_http_lua_main_conf_t * lmcf ;
354
+
357
355
idx = luaL_checkint (L , 2 );
358
356
359
357
dd ("index: %d" , idx );
@@ -363,8 +361,8 @@ ngx_http_lua_body_filter_param_get(lua_State *L)
363
361
return 1 ;
364
362
}
365
363
366
- lua_getglobal ( L , ngx_http_lua_chain_key );
367
- in = lua_touserdata ( L , -1 ) ;
364
+ lmcf = ngx_http_get_module_main_conf ( r , ngx_http_lua_module );
365
+ in = lmcf -> body_filter_chain ;
368
366
369
367
if (idx == 2 ) {
370
368
/* asking for the eof argument */
@@ -442,6 +440,8 @@ ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
442
440
ngx_chain_t * cl ;
443
441
ngx_chain_t * in ;
444
442
443
+ ngx_http_lua_main_conf_t * lmcf ;
444
+
445
445
idx = luaL_checkint (L , 2 );
446
446
447
447
dd ("index: %d" , idx );
@@ -450,13 +450,13 @@ ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
450
450
return luaL_error (L , "bad index: %d" , idx );
451
451
}
452
452
453
+ lmcf = ngx_http_get_module_main_conf (r , ngx_http_lua_module );
454
+
453
455
if (idx == 2 ) {
454
456
/* overwriting the eof flag */
455
457
last = lua_toboolean (L , 3 );
456
458
457
- lua_getglobal (L , ngx_http_lua_chain_key );
458
- in = lua_touserdata (L , -1 );
459
- lua_pop (L , 1 );
459
+ in = lmcf -> body_filter_chain ;
460
460
461
461
if (last ) {
462
462
ctx -> seen_last_in_filter = 1 ;
@@ -521,9 +521,7 @@ ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
521
521
case LUA_TNIL :
522
522
/* discard the buffers */
523
523
524
- lua_getglobal (L , ngx_http_lua_chain_key ); /* key val */
525
- in = lua_touserdata (L , -1 );
526
- lua_pop (L , 1 );
524
+ in = lmcf -> body_filter_chain ;
527
525
528
526
last = 0 ;
529
527
@@ -557,9 +555,7 @@ ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
557
555
lua_typename (L , type ));
558
556
}
559
557
560
- lua_getglobal (L , ngx_http_lua_chain_key );
561
- in = lua_touserdata (L , -1 );
562
- lua_pop (L , 1 );
558
+ in = lmcf -> body_filter_chain ;
563
559
564
560
last = 0 ;
565
561
@@ -625,8 +621,8 @@ ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
625
621
}
626
622
}
627
623
628
- lua_pushlightuserdata ( L , cl ) ;
629
- lua_setglobal ( L , ngx_http_lua_chain_key );
624
+ lmcf -> body_filter_chain = cl ;
625
+
630
626
return 0 ;
631
627
}
632
628
0 commit comments