Skip to content

Commit

Permalink
feat(var): add three variables that are indexed by default (#72)
Browse files Browse the repository at this point in the history
* `$http_x_kong_request_debug`
* `$http_x_kong_request_debug_token`
* `$http_x_kong_request_debug_log`
  • Loading branch information
chronolaw authored Mar 8, 2024
1 parent e25bfe3 commit 2fc1fdf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 5 additions & 0 deletions src/ngx_http_lua_kong_var_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
33 changes: 33 additions & 0 deletions t/006-default_indexed-var.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 2fc1fdf

Please sign in to comment.