]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] cookie: support client cookies with some contents appended to their value
authorWilly Tarreau <w@1wt.eu>
Wed, 6 Oct 2010 17:25:55 +0000 (19:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 30 Oct 2010 17:04:32 +0000 (19:04 +0200)
In all cookie persistence modes but prefix, we now support cookies whose
value is suffixed with some contents after a vertical bar ('|'). This will
be used to pass an optional expiration date. So as of now we only consider
the part of the cookie value which is used before the vertical bar.
(cherry picked from commit a4486bf4e5b03b5a980d03fef799f6407b2c992d)

include/common/defaults.h
src/proto_http.c

index 84ab3d48ae27fd8fa31406660f266f9bafba7c77..d1ce0214cab8e86a17f951b111a17f04e3702641 100644 (file)
 #define COOKIE_DELIM    '~'
 #endif
 
+// this delimitor is used between a server's name and a last visit date in
+// cookies exchanged with the client.
+#ifndef COOKIE_DELIM_DATE
+#define COOKIE_DELIM_DATE       '|'
+#endif
+
 #define CONN_RETRIES    3
 
 #define        CHK_CONNTIME    2000
index 4e4ac4db1f78825204ab68f325cb7cd195762ff9..bf81196a8671a100a911dc089a05ef77029a2ba6 100644 (file)
@@ -5922,10 +5922,14 @@ void manage_client_side_cookies(struct session *t, struct buffer *req)
                                }
                        }
 
-                       /* For cookies in prefix mode. The form is :
+                       /* Persistence cookies in passive, rewrite or insert mode have the
+                        * following form :
                         *
-                        *    Cookie: NAME=SRV~VALUE
+                        *    Cookie: NAME=SRV[|<lastseen>[|<firstseen>]]
+                        *
+                        * For cookies in prefix mode, the form is :
                         *
+                        *    Cookie: NAME=SRV~VALUE
                         */
                        if ((att_end - att_beg == t->be->cookie_len) && (t->be->cookie_name != NULL) &&
                            (memcmp(att_beg, t->be->cookie_name, att_end - att_beg) == 0)) {
@@ -5952,10 +5956,21 @@ void manage_client_side_cookies(struct session *t, struct buffer *req)
                                        for (delim = val_beg; delim < val_end; delim++)
                                                if (*delim == COOKIE_DELIM)
                                                        break;
-                               }
-                               else
+                               } else {
+                                       char *vbar1;
                                        delim = val_end;
-
+                                       /* Now check if the cookie contains a date field, which would
+                                        * appear after a vertical bar ('|') just after the server name
+                                        * and before the delimiter.
+                                        */
+                                       vbar1 = memchr(val_beg, COOKIE_DELIM_DATE, val_end - val_beg);
+                                       if (vbar1) {
+                                               /* OK, so left of the bar is the server's cookie and
+                                                * right is the last seen date.
+                                                */
+                                               delim = vbar1++;
+                                       }
+                               }
 
                                /* Here, we'll look for the first running server which supports the cookie.
                                 * This allows to share a same cookie between several servers, for example