]> git.pld-linux.org Git - packages/pound.git/blob - MultipleAddHeaderHonored.diff
- honour AddHeader if specified multiple times. patch from mailinglist
[packages/pound.git] / MultipleAddHeaderHonored.diff
1 honour AddHeader specified multiple times
2
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
5
6 AddHeader directive honored 
7
8 Francisco Ruiz <francisco.ruiz(at)juntaextremadura.es>  2011-11-15 22:41:48      [ SNIP ]
9  Hi,
10
11 I send a patch to the list so that it can be considered and merged to 
12 the main code if accepted.
13
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.
19
20 The patch sent:
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.
26
27 I hope it can be of any help for others.
28
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 
32 to merge it?
33
34 Thanks for pound and to all the community arround it.
35
36 -- 
37 Francisco Ruiz
38 francisco.ruiz(at)juntaextremadura.es
39
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
43 @@ -625,6 +625,7 @@
44  parse_HTTP(void)
45  {
46      char        lin[MAXBUF];
47 +    char        *ah;
48      LISTENER    *res;
49      SERVICE     *svc;
50      MATCHER     *m;
51 @@ -719,8 +720,18 @@
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);
61 +            }
62 +            else {
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);
66 +            }
67 +            free(res->add_head);
68 +            res->add_head = ah;
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)) {
72 @@ -772,6 +783,7 @@
73  parse_HTTPS(void)
74  {
75      char        lin[MAXBUF];
76 +    char        *ah;
77      LISTENER    *res;
78      SERVICE     *svc;
79      MATCHER     *m;
80 @@ -902,8 +914,18 @@
81              }
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);
90 +            }
91 +            else {
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);
95 +            }
96 +            free(res->add_head);
97 +            res->add_head = ah;
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
103 @@ -354,7 +354,7 @@
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
114 @@ -405,7 +405,7 @@
115  .TP
116  \fBAddHeader\fR "header: to add"
117  Add the defined header to the request passed to the back-end server. The header
118 -is added verbatim.
119 +is added verbatim.  Multiple headers can be added, one per AddHeader directive.
120  .TP
121  \fBRewriteLocation\fR 0|1|2
122  If 1 force
This page took 0.078859 seconds and 3 git commands to generate.