]> 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>
Thu, 3 Dec 2009 22:28:34 +0000 (23:28 +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.

doc/configuration.txt
src/cfgparse.c

index 7a3856c56f90cd9c8908150cbf50d0d450d538e0..18b024bc4127899bdb784059cb055c69a5817721 100644 (file)
@@ -1357,7 +1357,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
@@ -1439,7 +1439,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 b2e6145f5e188406798d2aaf647b7309f76076d7..bc9fdfecaaa99c732e81155c641aa5e810cafeef 100644 (file)
@@ -1306,7 +1306,21 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                                        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 {