changeset 1485:6e889910a5fe

cookies with longer paths go first in header
author corvid <corvid@lavabit.com>
date Wed, 30 Dec 2009 06:38:20 +0000
parents 29d892265da0
children 4fbeadf3191b
files dpi/cookies.c
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/dpi/cookies.c	Wed Dec 30 05:57:06 2009 +0000
+++ b/dpi/cookies.c	Wed Dec 30 06:38:20 2009 +0000
@@ -1202,7 +1202,20 @@
          }
          /* Check if the cookie matches the requesting URL */
          if (Cookies_match(cookie, url_port, path, is_ssl)) {
-            dList_append(matching_cookies, cookie);
+            int j;
+            CookieData_t *curr;
+            uint_t path_length = strlen(cookie->path);
+
+            /* "If multiple cookies satisfy the criteria [to be sent in a
+             * query], they are ordered in the Cookie header such that those
+             * with more specific Path attributes precede those with less
+             * specific."
+             */
+            for (j = 0;
+                 (curr = dList_nth_data(matching_cookies, j)) &&
+                  strlen(curr->path) >= path_length;
+                 j++) ;
+            dList_insert_pos(matching_cookies, cookie, j);
          }
       }
    }