lucian
lucian

Reputation: 681

Passing variable between blocks in Openresty/Lua with ngx.ctx

Trying to pass a variable between two lua blocks. Supposedly, this should work with ngx.ctx, like this:

header_filter_by_lua_block  {
ngx.ctx.myvar = ngx.header["X-fetch"];
}

access_by_lua_block  {
ngx.header["X-send"] = ngx.ctx.myvar;
}

but it doesn't. What's wrong?

P.S. Testing with both in one block does work (basically duplicating the existing header, but this is just for illustration)

header_filter_by_lua_block  {
ngx.ctx.myvar = ngx.header["X-fetch"];
ngx.header["X-send"] = ngx.ctx.myvar;
}

Upvotes: 0

Views: 1742

Answers (1)

Kousha
Kousha

Reputation: 36299

That's because access_by_lua_block runs before header_filter_by_lua_block.

Take a look at https://openresty-reference.readthedocs.io/en/latest/Directives/

Upvotes: 1

Related Questions