Skip to content

Commit ea49307

Browse files
committed
Add redirection io set header for apache
1 parent cf065f7 commit ea49307

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

Diff for: src/mod_redirectionio.c

+23
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static const char *redirectionio_set_logs_enable(cmd_parms *cmd, void *cfg, cons
3535
static const char *redirectionio_set_scheme(cmd_parms *cmd, void *cfg, const char *arg);
3636
static const char *redirectionio_set_show_rule_ids(cmd_parms *cmd, void *cfg, const char *arg);
3737
static const char *redirectionio_set_server(cmd_parms *cmd, void *dc, int argc, char *const argv[]);
38+
static const char *redirectionio_set_header(cmd_parms *cmd, void *cfg, const char *arg1, const char *arg2);
3839
static void redirectionio_apache_log_callback(const char* log_str, const void* data, short level);
3940
static apr_status_t redirectionio_atoi(const char *line, apr_size_t len);
4041

@@ -45,6 +46,7 @@ static const command_rec redirectionio_directives[] = {
4546
AP_INIT_TAKE1("redirectionioLogs", redirectionio_set_logs_enable, NULL, OR_ALL, "Enable or disable logging for redirectionio"),
4647
AP_INIT_TAKE1("redirectionioScheme", redirectionio_set_scheme, NULL, OR_ALL, "Force scheme to use when matching request"),
4748
AP_INIT_TAKE1("redirectionioRuleIdsHeader", redirectionio_set_show_rule_ids, NULL, OR_ALL, "Show rule ids used on response header"),
49+
AP_INIT_TAKE2("redirectionioSetHeader", redirectionio_set_header, NULL, OR_ALL, "Add header to match in redirectionio request"),
4850
{ NULL }
4951
};
5052

@@ -506,6 +508,7 @@ static void *create_redirectionio_dir_conf(apr_pool_t *pool, char *context) {
506508
config->server.timeout = RIO_TIMEOUT;
507509
config->pool = pool;
508510
config->show_rule_ids = -1;
511+
config->headers_set = NULL;
509512
}
510513

511514
return config;
@@ -523,6 +526,14 @@ static void *merge_redirectionio_dir_conf(apr_pool_t *pool, void *parent, void *
523526
conf->enable = conf_current->enable;
524527
}
525528

529+
if (conf_current->headers_set == NULL) {
530+
conf->headers_set = conf_parent->headers_set;
531+
} else if (conf_parent->headers_set == NULL) {
532+
conf->headers_set = conf_current->headers_set;
533+
} else {
534+
conf->headers_set = apr_table_overlay(pool, conf_current->headers_set, conf_parent->headers_set);
535+
}
536+
526537
if (conf_current->enable_logs == -1) {
527538
conf->enable_logs = conf_parent->enable_logs;
528539
} else {
@@ -806,6 +817,18 @@ static const char *redirectionio_set_server(cmd_parms *cmd, void *cfg, int argc,
806817
return NULL;
807818
}
808819

820+
static const char *redirectionio_set_header(cmd_parms *cmd, void *cfg, const char *arg1, const char *arg2) {
821+
redirectionio_config *conf = (redirectionio_config*)cfg;
822+
823+
if (conf->headers_set == NULL) {
824+
conf->headers_set = apr_table_make(conf->pool, 10);
825+
}
826+
827+
apr_table_set(conf->headers_set, arg1, arg2);
828+
829+
return NULL;
830+
}
831+
809832
static void redirectionio_apache_log_callback(const char* log_str, const void* data, short level) {
810833
if (level <= 1) {
811834
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, (request_rec *)data, "mod_redirectionio api error: %s", log_str);

Diff for: src/mod_redirectionio.h

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ typedef struct {
6161
int show_rule_ids;
6262
apr_reslist_t *connection_pool;
6363
apr_pool_t *pool;
64+
apr_table_t *headers_set;
6465
} redirectionio_config;
6566

6667
typedef struct {

Diff for: src/redirectionio_protocol.c

+26-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ apr_status_t redirectionio_protocol_match(redirectionio_connection *conn, redire
3333
struct REDIRECTIONIO_HeaderMap *first_header = NULL, *current_header = NULL;
3434
const char *request_serialized, *scheme;
3535
char *action_serialized;
36-
const apr_array_header_t *tarr = apr_table_elts(r->headers_in);
37-
const apr_table_entry_t *telts = (const apr_table_entry_t*)tarr->elts;
36+
const apr_array_header_t *tarr;
37+
const apr_table_entry_t *telts;
3838
int i;
3939
redirectionio_config *config = (redirectionio_config*) ap_get_module_config(r->per_dir_config, &redirectionio_module);
4040

4141
// Create request header map
42+
// First header from request
43+
tarr = apr_table_elts(r->headers_in);
44+
telts = (const apr_table_entry_t*)tarr->elts;
45+
4246
for (i = 0; i < tarr->nelts; i++) {
4347
current_header = (struct REDIRECTIONIO_HeaderMap *) apr_palloc(r->pool, sizeof(struct REDIRECTIONIO_HeaderMap));
4448

@@ -53,6 +57,26 @@ apr_status_t redirectionio_protocol_match(redirectionio_connection *conn, redire
5357
first_header = current_header;
5458
}
5559

60+
// Then header from config
61+
if (config->headers_set != NULL) {
62+
tarr = apr_table_elts(config->headers_set);
63+
telts = (const apr_table_entry_t*)tarr->elts;
64+
65+
for (i = 0; i < tarr->nelts; i++) {
66+
current_header = (struct REDIRECTIONIO_HeaderMap *) apr_palloc(r->pool, sizeof(struct REDIRECTIONIO_HeaderMap));
67+
68+
if (current_header == NULL) {
69+
return APR_EGENERAL;
70+
}
71+
72+
current_header->name = (const char *)telts[i].key;
73+
current_header->value = (const char *)telts[i].val;
74+
current_header->next = first_header;
75+
76+
first_header = current_header;
77+
}
78+
}
79+
5680
// Create redirection io request
5781
scheme = config->scheme;
5882

0 commit comments

Comments
 (0)