@@ -32,10 +32,6 @@ static void ngx_http_lua_body_filter_by_lua_env(lua_State *L,
3232static ngx_http_output_body_filter_pt ngx_http_next_body_filter ;
3333
3434
35- /* key for the ngx_chain_t *in pointer in the Lua thread */
36- #define ngx_http_lua_chain_key "__ngx_cl"
37-
38-
3935/**
4036 * Set environment table for the given code closure.
4137 *
@@ -51,12 +47,14 @@ static void
5147ngx_http_lua_body_filter_by_lua_env (lua_State * L , ngx_http_request_t * r ,
5248 ngx_chain_t * in )
5349{
54- /* set nginx request pointer to current lua thread's globals table */
50+ ngx_http_lua_main_conf_t * lmcf ;
51+
5552 ngx_http_lua_set_req (L , r );
5653
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 ;
5956
57+ #ifndef OPENRESTY_LUAJIT
6058 /**
6159 * we want to create empty environment for current script
6260 *
@@ -79,6 +77,7 @@ ngx_http_lua_body_filter_by_lua_env(lua_State *L, ngx_http_request_t *r,
7977 /* }}} */
8078
8179 lua_setfenv (L , -2 ); /* set new running env for the code closure */
80+ #endif /* OPENRESTY_LUAJIT */
8281}
8382
8483
@@ -236,8 +235,8 @@ ngx_http_lua_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
236235 ngx_int_t rc ;
237236 uint16_t old_context ;
238237 ngx_http_cleanup_t * cln ;
239- lua_State * L ;
240238 ngx_chain_t * out ;
239+ ngx_http_lua_main_conf_t * lmcf ;
241240
242241 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
243242 "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)
299298 return NGX_ERROR ;
300299 }
301300
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 ;
307303
308304 if (in == out ) {
309305 return ngx_http_next_body_filter (r , in );
@@ -345,7 +341,7 @@ ngx_http_lua_body_filter_init(void)
345341
346342
347343int
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 )
349345{
350346 u_char * data , * p ;
351347 size_t size ;
@@ -354,6 +350,8 @@ ngx_http_lua_body_filter_param_get(lua_State *L)
354350 int idx ;
355351 ngx_chain_t * in ;
356352
353+ ngx_http_lua_main_conf_t * lmcf ;
354+
357355 idx = luaL_checkint (L , 2 );
358356
359357 dd ("index: %d" , idx );
@@ -363,8 +361,8 @@ ngx_http_lua_body_filter_param_get(lua_State *L)
363361 return 1 ;
364362 }
365363
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 ;
368366
369367 if (idx == 2 ) {
370368 /* asking for the eof argument */
@@ -442,6 +440,8 @@ ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
442440 ngx_chain_t * cl ;
443441 ngx_chain_t * in ;
444442
443+ ngx_http_lua_main_conf_t * lmcf ;
444+
445445 idx = luaL_checkint (L , 2 );
446446
447447 dd ("index: %d" , idx );
@@ -450,13 +450,13 @@ ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
450450 return luaL_error (L , "bad index: %d" , idx );
451451 }
452452
453+ lmcf = ngx_http_get_module_main_conf (r , ngx_http_lua_module );
454+
453455 if (idx == 2 ) {
454456 /* overwriting the eof flag */
455457 last = lua_toboolean (L , 3 );
456458
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 ;
460460
461461 if (last ) {
462462 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,
521521 case LUA_TNIL :
522522 /* discard the buffers */
523523
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 ;
527525
528526 last = 0 ;
529527
@@ -557,9 +555,7 @@ ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
557555 lua_typename (L , type ));
558556 }
559557
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 ;
563559
564560 last = 0 ;
565561
@@ -625,8 +621,8 @@ ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
625621 }
626622 }
627623
628- lua_pushlightuserdata ( L , cl ) ;
629- lua_setglobal ( L , ngx_http_lua_chain_key );
624+ lmcf -> body_filter_chain = cl ;
625+
630626 return 0 ;
631627}
632628
0 commit comments