1 honour AddHeader specified multiple times
3 http://www.apsis.ch/pound/pound_list/index_html?query=addheader
4 http://www.apsis.ch/pound/pound_list/archive/2011/2011-11/1321393308000#1321393308000
6 AddHeader directive honored
8 Francisco Ruiz <francisco.ruiz(at)juntaextremadura.es> 2011-11-15 22:41:48 [ SNIP ]
11 I send a patch to the list so that it can be considered and merged to
12 the main code if accepted.
14 We need to add several headers to the request but it seems that
15 AddHeader just honors the last occurrence of the directive. Even more,
16 several AddHeader directives doesn't rise an error or warning. All of
17 them are processed and the string created with previus strdup() call
18 seems not to be freed.
21 * modify config.c to concatenate all the headers in the LISTENER
22 struct member add_head with the needed "\r\n".
23 * modify the comment to LISTENER struct member add_head to reflect
24 that AddHeader works also with HTTP an not only HTTPS, in pound.h
25 * modify man page pound.8 to reflect the changes.
27 I hope it can be of any help for others.
29 On the other hand, I would like to know about the patch that someone
30 send to the list to get sticky sessions by injecting cookies in the
31 replies to client, as other commercial products do. Are there any plans
34 Thanks for pound and to all the community arround it.
38 francisco.ruiz(at)juntaextremadura.es
40 Ahorrar papel protege el medio ambiente
41 --- config.c.orig 2010-02-02 12:49:02.000000000 +0100
42 +++ config.c 2011-11-14 21:52:49.000000000 +0100
52 conf_err("HeadRemove bad pattern - aborted");
53 } else if(!regexec(&AddHeader, lin, 4, matches, 0)) {
54 lin[matches[1].rm_eo] = '\0';
55 - if((res->add_head = strdup(lin + matches[1].rm_so)) == NULL)
56 - conf_err("AddHeader config: out of memory - aborted");
57 + if (res->add_head == NULL) {
58 + if ((ah = malloc (strlen(lin + matches[1].rm_so) + 1)) == NULL)
59 + conf_err("AddHeader config: out of memory - aborted");
60 + sprintf(ah, "%s", lin + matches[1].rm_so);
63 + if ((ah = malloc (strlen(res->add_head) + strlen(lin + matches[1].rm_so) + 1)) == NULL)
64 + conf_err("AddHeader config: out of memory - aborted");
65 + sprintf(ah, "%s\r\n%s", res->add_head, lin + matches[1].rm_so);
67 + free(res->add_head);
69 } else if(!regexec(&RewriteLocation, lin, 4, matches, 0)) {
70 res->rewr_loc = atoi(lin + matches[1].rm_so);
71 } else if(!regexec(&RewriteDestination, lin, 4, matches, 0)) {
82 } else if(!regexec(&AddHeader, lin, 4, matches, 0)) {
83 lin[matches[1].rm_eo] = '\0';
84 - if((res->add_head = strdup(lin + matches[1].rm_so)) == NULL)
85 - conf_err("AddHeader config: out of memory - aborted");
86 + if (res->add_head == NULL) {
87 + if ((ah = malloc (strlen(lin + matches[1].rm_so) + 1)) == NULL)
88 + conf_err("AddHeader config: out of memory - aborted");
89 + sprintf(ah, "%s", lin + matches[1].rm_so);
92 + if ((ah = malloc (strlen(res->add_head) + strlen(lin + matches[1].rm_so) + 1)) == NULL)
93 + conf_err("AddHeader config: out of memory - aborted");
94 + sprintf(ah, "%s\r\n%s", res->add_head, lin + matches[1].rm_so);
96 + free(res->add_head);
98 } else if(!regexec(&Ciphers, lin, 4, matches, 0)) {
99 lin[matches[1].rm_eo] = '\0';
100 SSL_CTX_set_cipher_list(res->ctx, lin + matches[1].rm_so);
101 --- pound.h.orig 2010-02-02 12:49:02.000000000 +0100
102 +++ pound.h 2011-11-15 21:40:40.000000000 +0100
104 SSL_CTX *ctx; /* CTX for SSL connections */
105 int clnt_check; /* client verification mode */
106 int noHTTPS11; /* HTTP 1.1 mode for SSL */
107 - char *add_head; /* extra SSL header */
108 + char *add_head; /* extra headers */
109 regex_t verb; /* pattern to match the request verb against */
110 int to; /* client time-out */
111 int has_pat; /* was a URL pattern defined? */
112 --- pound.8.orig 2010-02-02 12:49:02.000000000 +0100
113 +++ pound.8 2011-11-15 21:48:02.000000000 +0100
116 \fBAddHeader\fR "header: to add"
117 Add the defined header to the request passed to the back-end server. The header
119 +is added verbatim. Multiple headers can be added, one per AddHeader directive.
121 \fBRewriteLocation\fR 0|1|2