diff --git a/src/ngx_http_lua_kong_request_id.c b/src/ngx_http_lua_kong_request_id.c index 94245ab0..fe8161a4 100644 --- a/src/ngx_http_lua_kong_request_id.c +++ b/src/ngx_http_lua_kong_request_id.c @@ -22,6 +22,21 @@ #define KONG_REQUEST_ID_FORMAT "%08xD%08xD%08xD%08xD" +static ngx_int_t +ngx_http_lua_kong_variable_request_id(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data); + + +static ngx_http_variable_t ngx_http_lua_kong_variables[] = { + + { ngx_string("kong_request_id"), NULL, + ngx_http_lua_kong_variable_request_id, + 0, 0, 0 }, + + ngx_http_null_variable +}; + + static ngx_int_t ngx_http_lua_kong_variable_request_id(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) @@ -48,3 +63,21 @@ ngx_http_lua_kong_variable_request_id(ngx_http_request_t *r, } +ngx_int_t +ngx_http_lua_kong_add_vars(ngx_conf_t *cf) +{ + ngx_http_variable_t *cv, *v; + + for (cv = ngx_http_lua_kong_variables; cv->name.len; cv++) { + v = ngx_http_add_variable(cf, &cv->name, cv->flags); + if (v == NULL) { + return NGX_ERROR; + } + + *v = *cv; + } + + return NGX_OK; +} + +