Skip to content

Commit 164807a

Browse files
committed
first commit
1 parent cdee98e commit 164807a

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/ngx_http_apisix_log_handler.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "ngx_http_apisix_module.h"
2+
3+
char *
4+
ngx_http_apisix_error_log_request_id(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
5+
{
6+
ngx_str_t *value;
7+
ngx_http_apisix_loc_conf_t *loc_conf = conf;
8+
9+
value = cf->args->elts;
10+
if (value[1].data[0] != '$') {
11+
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid variable name \"%V\"", &value[1]);
12+
return NGX_CONF_ERROR;
13+
}
14+
15+
value[1].len--;
16+
}

src/ngx_http_apisix_module.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <ngx_config.h>
22
#include <ngx_core.h>
33
#include <ngx_http.h>
4-
#include <ngx_http_realip_module.h>
4+
#include <ngx_http_realip_module.c>
55
#include "ngx_http_apisix_module.h"
6-
6+
#include "ngx_http_apisix_log_handler.c"
77

88
#define NGX_HTTP_APISIX_SSL_ENC 1
99
#define NGX_HTTP_APISIX_SSL_SIGN 2
@@ -33,7 +33,13 @@ static ngx_command_t ngx_http_apisix_cmds[] = {
3333
NGX_HTTP_LOC_CONF_OFFSET,
3434
offsetof(ngx_http_apisix_loc_conf_t, delay_client_max_body_check),
3535
NULL },
36-
36+
{ ngx_string("apisix_error_log_request_id"),
37+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
38+
ngx_http_apisix_error_log_request_id, //TODO: Implement this setup function
39+
NGX_HTTP_LOC_CONF_OFFSET,
40+
offsetof(ngx_http_apisix_loc_conf_t, request_id_var_index),
41+
NULL
42+
},
3743
ngx_null_command
3844
};
3945

@@ -100,7 +106,7 @@ ngx_http_apisix_create_loc_conf(ngx_conf_t *cf)
100106
}
101107

102108
conf->delay_client_max_body_check = NGX_CONF_UNSET;
103-
109+
conf->request_id_var_index = NGX_CONF_UNSET;
104110
return conf;
105111
}
106112

@@ -111,6 +117,7 @@ ngx_http_apisix_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
111117
ngx_http_apisix_loc_conf_t *prev = parent;
112118
ngx_http_apisix_loc_conf_t *conf = child;
113119

120+
ngx_conf_merge_value(conf->request_id_var_index, prev->request_id_var_index, NGX_CONF_UNSET);
114121
ngx_conf_merge_value(conf->delay_client_max_body_check,
115122
prev->delay_client_max_body_check, 0);
116123

src/ngx_http_apisix_module.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
typedef struct {
99
ngx_flag_t delay_client_max_body_check;
10+
ngx_int_t request_id_var_index;
11+
1012
} ngx_http_apisix_loc_conf_t;
1113

1214

@@ -57,5 +59,6 @@ ngx_int_t ngx_http_apisix_is_body_filter_by_lua_skipped(ngx_http_request_t *r);
5759

5860
ngx_flag_t ngx_http_apisix_is_ntls_enabled(ngx_http_conf_ctx_t *conf_ctx);
5961

62+
char * ngx_http_apisix_error_log_request_id(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
6063

6164
#endif /* _NGX_HTTP_APISIX_H_INCLUDED_ */

0 commit comments

Comments
 (0)