]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] config: support passing multiple "domain" statements to cookies
authorWilly Tarreau <w@1wt.eu>
Thu, 3 Dec 2009 22:28:34 +0000 (23:28 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 6 Dec 2009 12:25:23 +0000 (13:25 +0100)
In some environments it is not possible to rely on any wildcard for a
domain name (eg: .com, .net, .fr...) so it is required to send multiple
domain extensions. (Un)fortunately the syntax check on the domain name
prevented that from being done the dirty way. So let's just build a
domain list when multiple domains are passed on the same line.
(cherry picked from commit 950245ca2b772fd6b99b8152c48c694ed0212857)

doc/configuration.txt
src/cfgparse.c

index 47842d6c76ebce0f86527bf91624625890b3529e..3c6dd642eb6db69c54e83e9054c5e3c48d1e9025 100644 (file)
@@ -1503,7 +1503,7 @@ contimeout <timeout>
 
 
 cookie <name> [ rewrite | insert | prefix ] [ indirect ] [ nocache ]
-              [ postonly ] [ domain <domain> ]
+              [ postonly ] [ domain <domain> ]*
   Enable cookie-based persistence in a backend.
   May be used in sections :   defaults | frontend | listen | backend
                                  yes   |    no    |   yes  |   yes
@@ -1585,7 +1585,12 @@ cookie <name> [ rewrite | insert | prefix ] [ indirect ] [ nocache ]
 
     domain    This option allows to specify the domain at which a cookie is
               inserted. It requires exactly one paramater: a valid domain
-              name.
+              name. If the domain begins with a dot, the browser is allowed to
+              use it for any host ending with that name. It is also possible to
+              specify several domain names by invoking this option multiple
+              times. Some browsers might have small limits on the number of
+              domains, so be careful when doing that. For the record, sending
+              10 domains to MSIE 6 or Firefox 2 works as expected.
 
   There can be only one persistence cookie per HTTP backend, and it can be
   declared in a defaults section. The value of the cookie will be the value
index d433ea314c260756e96b1a6b9afc8f254bbfbee0..e74b7687afb40c18ae5e37641854b92b94752d59 100644 (file)
@@ -1475,7 +1475,21 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                        goto out;
                                }
 
-                               curproxy->cookie_domain = strdup(args[cur_arg + 1]);
+                               if (!curproxy->cookie_domain) {
+                                       curproxy->cookie_domain = strdup(args[cur_arg + 1]);
+                               } else {
+                                       /* one domain was already specified, add another one by
+                                        * building the string which will be returned along with
+                                        * the cookie.
+                                        */
+                                       char *new_ptr;
+                                       int new_len = strlen(curproxy->cookie_domain) +
+                                               strlen("; domain=") + strlen(args[cur_arg + 1]) + 1;
+                                       new_ptr = malloc(new_len);
+                                       snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]);
+                                       free(curproxy->cookie_domain);
+                                       curproxy->cookie_domain = new_ptr;
+                               }
                                cur_arg++;
                        }
                        else {