From 85d45de710dda0e9b20b2834cc6e46090fb8f2ce Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 12 Oct 2023 17:49:57 +0800 Subject: [PATCH 1/3] feat(src): add more indexed vars --- README.md | 3 +++ src/ngx_http_lua_kong_var_index.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 2bdacac3..a6cf30f8 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,9 @@ index *commonly used variables* as follows: - `$http_x_forwarded_port` - `$http_x_forwarded_prefix` - `$http_x_forwarded_proto` +- `$http_x_kong_request_debug` +- `$http_x_kong_request_debug_token` +- `$http_x_kong_request_debug_log` - `$https` - `$http2` - `$realip_remote_addr` diff --git a/src/ngx_http_lua_kong_var_index.c b/src/ngx_http_lua_kong_var_index.c index eb9a8c29..f9d3d9f4 100644 --- a/src/ngx_http_lua_kong_var_index.c +++ b/src/ngx_http_lua_kong_var_index.c @@ -44,6 +44,11 @@ static ngx_str_t default_vars[] = { ngx_string("http_x_forwarded_prefix"), ngx_string("http_x_forwarded_proto"), + /* for request-debugging */ + ngx_string("http_x_kong_request_debug"), + ngx_string("http_x_kong_request_debug_token"), + ngx_string("http_x_kong_request_debug_log"), + /* --with-http_ssl_module */ #if (NGX_HTTP_SSL) ngx_string("https"), From 6c5515ddf78f2ce69188d20af184f44c494ee92d Mon Sep 17 00:00:00 2001 From: chronolaw Date: Mon, 26 Feb 2024 11:05:57 +0800 Subject: [PATCH 2/3] add test cases --- t/006-default_indexed-var.t | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/t/006-default_indexed-var.t b/t/006-default_indexed-var.t index 2ca6bdd1..9c07fb99 100644 --- a/t/006-default_indexed-var.t +++ b/t/006-default_indexed-var.t @@ -411,3 +411,36 @@ get variable value '0' by index [error] [crit] [alert] + +=== TEST 13: variable $http_x_kong_request_debug, $http_x_kong_request_debug_token, $http_x_kong_request_debug_log +--- http_config + lua_package_path "../lua-resty-core/lib/?.lua;lualib/?.lua;;"; + lua_kong_load_var_index default; + init_by_lua_block { + require("resty.kong.var").patch_metatable() + } + +--- config + location = /test { + content_by_lua_block { + ngx.say(ngx.var.http_x_kong_request_debug, " ", + ngx.var.http_x_kong_request_debug_token, " ", + ngx.var.http_x_kong_request_debug_log) + } + } +--- request +GET /test +--- more_headers +x-kong-request-debug: true +x-kong-request-debug_token: 12345 +x_kong_request_debug_log: false +--- response_body +true 12345 false +--- error_log +get variable value 'true' by index +get variable value '12345' by index +get variable value 'false' by index +--- no_error_log +[error] +[crit] +[alert] From dbba991fc6d089d84bbd2d17c925aba51e2decbe Mon Sep 17 00:00:00 2001 From: chronolaw Date: Mon, 26 Feb 2024 11:15:32 +0800 Subject: [PATCH 3/3] fix tests --- t/006-default_indexed-var.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/006-default_indexed-var.t b/t/006-default_indexed-var.t index 9c07fb99..cdecae40 100644 --- a/t/006-default_indexed-var.t +++ b/t/006-default_indexed-var.t @@ -432,8 +432,8 @@ get variable value '0' by index GET /test --- more_headers x-kong-request-debug: true -x-kong-request-debug_token: 12345 -x_kong_request_debug_log: false +x-kong-request-debug-token: 12345 +x-kong-request-debug-log: false --- response_body true 12345 false --- error_log