Project

General

Profile

Feature #2295 ยป patch-mod_setenv.c

set-request-header patch for mod_setenv.c - mm, 2011-02-07 11:35

 
1
--- src/mod_setenv.c.orig	2010-08-17 11:04:38.000000000 +0200
2
+++ src/mod_setenv.c	2011-02-07 11:20:28.368639616 +0100
3
@@ -20,6 +20,8 @@
4
 	array *response_header;
5
 
6
 	array *environment;
7
+
8
+	array *request_header_set;
9
 } plugin_config;
10
 
11
 typedef struct {
12
@@ -70,6 +72,7 @@
13
 			array_free(s->request_header);
14
 			array_free(s->response_header);
15
 			array_free(s->environment);
16
+			array_free(s->request_header_set);
17
 
18
 			free(s);
19
 		}
20
@@ -91,6 +94,7 @@
21
 		{ "setenv.add-request-header",  NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
22
 		{ "setenv.add-response-header", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 1 */
23
 		{ "setenv.add-environment",     NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 2 */
24
+		{ "setenv.set-request-header",  NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 3 */
25
 		{ NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
26
 	};
27
 
28
@@ -102,13 +106,15 @@
29
 		plugin_config *s;
30
 
31
 		s = calloc(1, sizeof(plugin_config));
32
-		s->request_header   = array_init();
33
-		s->response_header  = array_init();
34
-		s->environment      = array_init();
35
+		s->request_header       = array_init();
36
+		s->response_header      = array_init();
37
+		s->environment          = array_init();
38
+		s->request_header_set   = array_init();
39
 
40
 		cv[0].destination = s->request_header;
41
 		cv[1].destination = s->response_header;
42
 		cv[2].destination = s->environment;
43
+		cv[3].destination = s->request_header_set;
44
 
45
 		p->config_storage[i] = s;
46
 
47
@@ -129,6 +135,7 @@
48
 	PATCH(request_header);
49
 	PATCH(response_header);
50
 	PATCH(environment);
51
+	PATCH(request_header_set);
52
 
53
 	/* skip the first, the global context */
54
 	for (i = 1; i < srv->config_context->used; i++) {
55
@@ -148,7 +155,9 @@
56
 				PATCH(response_header);
57
 			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.add-environment"))) {
58
 				PATCH(environment);
59
-			}
60
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("setenv.set-request-header"))) {
61
+				PATCH(request_header_set);
62
+            }
63
 		}
64
 	}
65
 
66
@@ -211,6 +220,25 @@
67
 		response_header_insert(srv, con, CONST_BUF_LEN(ds->key), CONST_BUF_LEN(ds->value));
68
 	}
69
 
70
+	for (k = 0; k < p->conf.request_header_set->used; k++) {
71
+		data_string *ds = (data_string *)p->conf.request_header_set->data[k];
72
+		data_string *ds_dst;
73
+
74
+		if (NULL != (ds_dst = (data_string *)array_get_element(con->request.headers, ds->key->ptr))) {
75
+            // mod the header
76
+            buffer_copy_string_buffer(ds_dst->value, ds->value);
77
+            continue;
78
+		}
79
+
80
+        // insert a header
81
+
82
+        ds_dst = data_string_init();
83
+		buffer_copy_string_buffer(ds_dst->key, ds->key);
84
+		buffer_copy_string_buffer(ds_dst->value, ds->value);
85
+
86
+		array_insert_unique(con->request.headers, (data_unset *)ds_dst);
87
+	}
88
+
89
 	/* not found */
90
 	return HANDLER_GO_ON;
91
 }
    (1-1/1)