Skip to content

Commit 29eb556

Browse files
committed
Add possibility to show rule ids in header
1 parent 47841f6 commit 29eb556

5 files changed

+40
-5
lines changed

nginx-test.conf.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ http {
3131

3232
redirectionio on;
3333
redirectionio_project_key 58056a48-664d-11e7-aeb0-0242ac130004;
34+
redirectionio_add_rule_ids_header on;
3435
redirectionio_pass agent:10301;
3536

3637
location /noredirection {

src/ngx_http_redirectionio_module.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ static ngx_command_t ngx_http_redirectionio_commands[] = {
5353
offsetof(ngx_http_redirectionio_conf_t, enable_logs),
5454
ngx_http_redirectionio_enable_state
5555
},
56+
{
57+
ngx_string("redirectionio_add_rule_ids_header"),
58+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
59+
ngx_conf_set_enum_slot,
60+
NGX_HTTP_LOC_CONF_OFFSET,
61+
offsetof(ngx_http_redirectionio_conf_t, show_rule_ids),
62+
ngx_http_redirectionio_enable_state
63+
},
5664
{
5765
ngx_string("redirectionio_pass"),
5866
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
@@ -61,6 +69,14 @@ static ngx_command_t ngx_http_redirectionio_commands[] = {
6169
offsetof(ngx_http_redirectionio_conf_t, pass),
6270
NULL
6371
},
72+
{
73+
ngx_string("redirectionio_scheme"),
74+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
75+
ngx_conf_set_str_slot,
76+
NGX_HTTP_LOC_CONF_OFFSET,
77+
offsetof(ngx_http_redirectionio_conf_t, scheme),
78+
NULL
79+
},
6480
ngx_null_command /* command termination */
6581
};
6682

@@ -321,6 +337,7 @@ static void *ngx_http_redirectionio_create_conf(ngx_conf_t *cf) {
321337

322338
conf->enable = NGX_CONF_UNSET_UINT;
323339
conf->enable_logs = NGX_CONF_UNSET_UINT;
340+
conf->show_rule_ids = NGX_CONF_UNSET_UINT;
324341

325342
return conf;
326343
}
@@ -330,7 +347,9 @@ static char *ngx_http_redirectionio_merge_conf(ngx_conf_t *cf, void *parent, voi
330347
ngx_http_redirectionio_conf_t *conf = child;
331348

332349
ngx_conf_merge_uint_value(conf->enable_logs, prev->enable_logs, NGX_HTTP_REDIRECTIONIO_ON);
350+
ngx_conf_merge_uint_value(conf->show_rule_ids, prev->show_rule_ids, NGX_HTTP_REDIRECTIONIO_OFF);
333351
ngx_conf_merge_str_value(conf->project_key, prev->project_key, "");
352+
ngx_conf_merge_str_value(conf->scheme, prev->scheme, "");
334353

335354
if (conf->pass.url.data == NULL) {
336355
if (prev->pass.url.data) {

src/ngx_http_redirectionio_module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ typedef struct {
4040
ngx_uint_t enable;
4141
ngx_uint_t enable_logs;
4242
ngx_str_t project_key;
43+
ngx_str_t scheme;
44+
ngx_uint_t show_rule_ids;
4345
ngx_http_complex_value_t *complex_target;
4446
ngx_url_t pass;
4547
ngx_reslist_t *connection_pool;

src/ngx_http_redirectionio_module_filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ngx_int_t ngx_http_redirectionio_headers_filter(ngx_http_request_t *r) {
5353

5454
conf = ngx_http_get_module_loc_conf(r, ngx_http_redirectionio_module);
5555

56-
if (conf->enable == NGX_HTTP_REDIRECTIONIO_OFF) {
56+
if (conf == NULL || conf->enable == NGX_HTTP_REDIRECTIONIO_OFF) {
5757
return ngx_http_next_header_filter(r);
5858
}
5959

@@ -106,7 +106,7 @@ ngx_int_t ngx_http_redirectionio_headers_filter(ngx_http_request_t *r) {
106106
}
107107

108108
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http redirectionio filtering on response status code %d", r->headers_out.status);
109-
first_header = (struct REDIRECTIONIO_HeaderMap *)redirectionio_action_header_filter_filter(ctx->action, first_header, r->headers_out.status);
109+
first_header = (struct REDIRECTIONIO_HeaderMap *)redirectionio_action_header_filter_filter(ctx->action, first_header, r->headers_out.status, conf->show_rule_ids == NGX_HTTP_REDIRECTIONIO_ON);
110110

111111
if (first_header == NULL) {
112112
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http redirectionio no filter to add");

src/ngx_http_redirectionio_protocol.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ void ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_http_re
2222
ngx_list_part_t *part;
2323
struct REDIRECTIONIO_HeaderMap *first_header = NULL, *current_header = NULL;
2424
const char *request_serialized;
25-
char *method, *uri, *host = NULL, *scheme = "http";
25+
char *method, *uri, *host = NULL, *scheme = NULL;
2626
ngx_uint_t i;
2727
ngx_pool_cleanup_t *cln;
28+
ngx_http_redirectionio_conf_t *conf;
29+
30+
conf = ngx_http_get_module_loc_conf(r, ngx_http_redirectionio_module);
31+
32+
if (conf == NULL) {
33+
return;
34+
}
2835

2936
// Create header map
3037
part = &r->headers_in.headers.part;
@@ -53,11 +60,17 @@ void ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_http_re
5360
first_header = current_header;
5461
}
5562

56-
#if (NGX_HTTP_SSL)
63+
if (conf->scheme.len > 0) {
64+
scheme = ngx_str_to_char(&conf->scheme, r->pool);
65+
} else {
66+
scheme = "http";
67+
}
68+
69+
#if (NGX_HTTP_SSL)
5770
if (r->connection->ssl) {
5871
scheme = "https";
5972
}
60-
#endif
73+
#endif
6174

6275
uri = ngx_str_to_char(&r->unparsed_uri, r->pool);
6376
method = ngx_str_to_char(&r->method_name, r->pool);

0 commit comments

Comments
 (0)