diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3
index bc81ac8..c3e594f 100644
--- a/docs/libcurl/curl_easy_setopt.3
+++ b/docs/libcurl/curl_easy_setopt.3
@@ -1510,6 +1510,11 @@ Passing the special string \&"SESS" will only erase all session cookies known
 by cURL. (Added in 7.15.4) Passing the special string \&"FLUSH" will write
 all cookies known by cURL to the file specified by \fICURLOPT_COOKIEJAR\fP.
 (Added in 7.17.1)
+.IP CURLOPT_MAXCOOKIES
+Pass a long. The set number will be the maximam number of cookies.
+If that many cookies received, this will delete the oldest access cookie.
+Set it to 0 for an infinite number of cookies (which is the default).
+(Added in 7.3x.x)
 .IP CURLOPT_HTTPGET
 Pass a long. If the long is 1, this forces the HTTP request to get back
 to GET. Usable if a POST, HEAD, PUT, or a custom request has been used
diff --git a/docs/libcurl/curl_share_setopt.3 b/docs/libcurl/curl_share_setopt.3
index c196743..b21b8aa 100644
--- a/docs/libcurl/curl_share_setopt.3
+++ b/docs/libcurl/curl_share_setopt.3
@@ -77,6 +77,11 @@ the same as those for \fICURLSHOPT_SHARE\fP.
 .IP CURLSHOPT_USERDATA
 The \fIparameter\fP allows you to specify a pointer to data that will be passed
 to the lock_function and unlock_function each time it is called.
+.IP CURLSHOPT_MAXCOOKIES
+Pass a long. The set number will be the maximam number of cookies.
+If that many cookies received, this will delete the oldest access cookie.
+Set it to 0 for an infinite number of cookies (which is the default).
+(Added in 7.3x.x)
 .SH RETURN VALUE
 CURLSHE_OK (zero) means that the option was set properly, non-zero means an
 error occurred as \fI<curl/curl.h>\fP defines. See the \fIlibcurl-errors.3\fP
diff --git a/include/curl/curl.h b/include/curl/curl.h
index e8ec9ee..515c755 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -1533,6 +1533,9 @@ typedef enum {
   /* Enable/disable SASL initial response */
   CINIT(SASL_IR, LONG, 218),
 
+  /* number of maximam cookies, 0 means no limit */
+  CINIT(MAXCOOKIES, LONG, 219),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
@@ -2078,6 +2081,7 @@ typedef enum {
   CURLSHOPT_UNLOCKFUNC, /* pass in a 'curl_unlock_function' pointer */
   CURLSHOPT_USERDATA,   /* pass in a user data pointer used in the lock/unlock
                            callback functions */
+  CURLSHOPT_MAXCOOKIES, /* set number of maximam cookies, 0 means no limit */
   CURLSHOPT_LAST  /* never use */
 } CURLSHoption;
 
diff --git a/lib/cookie.c b/lib/cookie.c
index a67204e..6191d70 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -155,7 +155,8 @@ void Curl_cookie_loadfiles(struct SessionHandle *data)
       data->cookies = Curl_cookie_init(data,
                                        list->data,
                                        data->cookies,
-                                       data->set.cookiesession);
+                                       data->set.cookiesession,
+                                       data->set.maxcookies);
       list = list->next;
     }
     curl_slist_free_all(data->change.cookielist); /* clean up list */
@@ -177,6 +178,77 @@ static void strstore(char **str, const char *newstr)
   *str = strdup(newstr);
 }
 
+/*
+ * remove_expired() removes expired cookies.
+ */
+static void remove_expired(struct CookieInfo *cookies)
+{
+  struct Cookie *co, *nx, *pv;
+  long now = (long)time(NULL);
+
+  co = cookies->cookies;
+  pv = NULL;
+  while(co) {
+    nx = co->next;
+    if((co->expirestr || co->maxage) && co->expires < now) {
+      if(co == cookies->cookies) {
+        cookies->cookies = co->next;
+      }
+      else {
+        pv->next = co->next;
+      }
+      cookies->numcookies--;
+      freecookie(co);
+    }
+    else {
+      pv = co;
+    }
+    co = nx;
+  }
+}
+
+static int access_sort(const void *p1, const void *p2)
+{
+  struct Cookie *c1 = *(struct Cookie **)p1;
+  struct Cookie *c2 = *(struct Cookie **)p2;
+
+  if(c2->access_time > c1->access_time)
+    return -1;
+  else if (c2->access_time < c1->access_time)
+    return 1;
+  return 0;
+}
+
+static void access_time_sort(struct CookieInfo *info)
+{
+  struct Cookie *co = info->cookies;
+  struct Cookie **array;
+  size_t i;
+  size_t num;
+
+  if(0 == info->maxcookies || info->numcookies <= info->maxcookies)
+    return;
+
+  num = info->numcookies;
+
+  /* alloc an array and store all cookie pointers */
+  array = malloc(sizeof(struct Cookie *) * info->numcookies);
+  if(!array)
+    return;
+
+  for(i=0; co; co = co->next)
+    array[i++] = co;
+
+  /* now sort the cookie pointers in path length order */
+  qsort(array, info->numcookies, sizeof(struct Cookie *), access_sort);
+
+  info->cookies = array[0]; /* start here */
+  for(i=0; i<num-1; i++)
+    array[i]->next = array[i+1];
+  array[num-1]->next = NULL; /* terminate the list */
+
+  free(array); /* remove the temporary data again */
+}
 
 /****************************************************************************
  *
@@ -217,6 +289,8 @@ Curl_cookie_add(struct SessionHandle *data,
   if(!co)
     return NULL; /* bail out if we're this low on memory */
 
+  co->access_time = (curl_off_t)now;
+
   if(httpheader) {
     /* This line was read off a HTTP-header */
     const char *ptr;
@@ -611,6 +685,9 @@ Curl_cookie_add(struct SessionHandle *data,
      superceeds an already existing cookie, which it may if the previous have
      the same domain and path as this */
 
+  /* at first, remove expired cookies */
+  remove_expired(c);
+
   clist = c->cookies;
   replace_old = FALSE;
   while(clist) {
@@ -704,6 +781,22 @@ Curl_cookie_add(struct SessionHandle *data,
     else
       c->cookies = co;
     c->numcookies++; /* one more cookie in the jar */
+
+    access_time_sort(c);
+
+    /* then, if cookies are more than c->maxcookies, delete oldest. */
+    /* note: maxcookies is zero means infinity. */
+    while(c->maxcookies && c->maxcookies < c->numcookies) {
+      co = c->cookies;
+      if(co) {
+        c->cookies = co->next;
+        c->numcookies--;
+        freecookie(co);
+        if(c->numcookies == c->maxcookies) {
+          co = c->cookies;
+        }
+      }
+    }
   }
 
   return co;
@@ -722,7 +815,7 @@ Curl_cookie_add(struct SessionHandle *data,
 struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
                                     const char *file,
                                     struct CookieInfo *inc,
-                                    bool newsession)
+                                    bool newsession, int maxcookies)
 {
   struct CookieInfo *c;
   FILE *fp;
@@ -754,6 +847,8 @@ struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
 
   c->newsession = newsession; /* new session? */
 
+  c->maxcookies = maxcookies;
+
   if(fp) {
     char *lineptr;
     bool headerline;
@@ -840,6 +935,9 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
   if(!c || !c->cookies)
     return NULL; /* no cookie struct or no cookies in the struct */
 
+  /* at first, remove expired cookies */
+  remove_expired(c);
+
   co = c->cookies;
 
   while(co) {
@@ -878,6 +976,9 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
             mainco = newco;
 
             matches++;
+
+            /* update access_time */
+            co->access_time = (curl_off_t)now;
           }
           else {
             fail:
@@ -1085,6 +1186,9 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
        destination file */
     return 0;
 
+  /* at first, remove expired cookies */
+  remove_expired(c);
+
   if(strequal("-", dumphere)) {
     /* use stdout */
     out = stdout;
@@ -1136,6 +1240,9 @@ struct curl_slist *Curl_cookie_list(struct SessionHandle *data)
       (data->cookies->numcookies == 0))
     return NULL;
 
+  /* at first, remove expired cookies */
+  remove_expired(data->cookies);
+
   c = data->cookies->cookies;
 
   while(c) {
diff --git a/lib/cookie.h b/lib/cookie.h
index d3b63f7..46de537 100644
--- a/lib/cookie.h
+++ b/lib/cookie.h
@@ -42,6 +42,8 @@ struct Cookie {
   bool secure;       /* whether the 'secure' keyword was used */
   bool livecookie;   /* updated from a server, not a stored file */
   bool httponly;     /* true if the httponly directive is present */
+
+  curl_off_t access_time;  /* cookie access time */
 };
 
 struct CookieInfo {
@@ -52,6 +54,9 @@ struct CookieInfo {
   bool running;    /* state info, for cookie adding information */
   long numcookies; /* number of cookies in the "jar" */
   bool newsession; /* new session, discard session cookies on load */
+
+  long maxcookies; /* number of maximam cookies in the "jar".
+                      0 means no limit */
 };
 
 /* This is the maximum line length we accept for a cookie line. RFC 2109
@@ -88,14 +93,15 @@ void Curl_cookie_clearsess(struct CookieInfo *cookies);
 #if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
 #define Curl_cookie_list(x) NULL
 #define Curl_cookie_loadfiles(x) Curl_nop_stmt
-#define Curl_cookie_init(x,y,z,w) NULL
+#define Curl_cookie_init(x,y,z,w,v) NULL
 #define Curl_cookie_cleanup(x) Curl_nop_stmt
 #define Curl_flush_cookies(x,y) Curl_nop_stmt
 #else
 void Curl_flush_cookies(struct SessionHandle *data, int cleanup);
 void Curl_cookie_cleanup(struct CookieInfo *);
 struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
-                                    const char *, struct CookieInfo *, bool);
+                                    const char *, struct CookieInfo *,
+                                    bool, int);
 struct curl_slist *Curl_cookie_list(struct SessionHandle *data);
 void Curl_cookie_loadfiles(struct SessionHandle *data);
 #endif
diff --git a/lib/easy.c b/lib/easy.c
index eb45bd7..c589b3f 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -584,7 +584,8 @@ CURL *curl_easy_duphandle(CURL *incurl)
     outcurl->cookies = Curl_cookie_init(data,
                                         data->cookies->filename,
                                         outcurl->cookies,
-                                        data->set.cookiesession);
+                                        data->set.cookiesession,
+                                        data->set.maxcookies);
     if(!outcurl->cookies)
       goto fail;
   }
diff --git a/lib/share.c b/lib/share.c
index b21c9f6..ec180e4 100644
--- a/lib/share.c
+++ b/lib/share.c
@@ -52,6 +52,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
   curl_unlock_function unlockfunc;
   void *ptr;
   CURLSHcode res = CURLSHE_OK;
+  long value;
 
   if(share->dirty)
     /* don't allow setting options while one or more handles are already
@@ -77,7 +78,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
     case CURL_LOCK_DATA_COOKIE:
 #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
       if(!share->cookies) {
-        share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE );
+        share->cookies = Curl_cookie_init(NULL, NULL, NULL, TRUE, 0);
         if(!share->cookies)
           res = CURLSHE_NOMEM;
       }
@@ -164,6 +165,17 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
     share->clientdata = ptr;
     break;
 
+  case CURLSHOPT_MAXCOOKIES:
+    value = va_arg(param, long);
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
+    if(share->cookies && 0 <= value) {
+      share->cookies->maxcookies = value;
+    }
+#else   /* CURL_DISABLE_HTTP || CURL_DISABLE_COOKIES */
+    res = CURLSHE_NOT_BUILT_IN;
+#endif
+    break;
+
   default:
     res = CURLSHE_BAD_OPTION;
     break;
diff --git a/lib/url.c b/lib/url.c
index e116a5b..0391f3f 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -1109,7 +1109,8 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
      * have been made.
      */
     data->cookies = Curl_cookie_init(data, NULL, data->cookies,
-                                     data->set.cookiesession);
+                                     data->set.cookiesession,
+                                     data->set.maxcookies);
     break;
 
   case CURLOPT_COOKIESESSION:
@@ -1155,7 +1156,8 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
 
     if(!data->cookies)
       /* if cookie engine was not running, activate it */
-      data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE);
+      data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE,
+                                       data->set.maxcookies);
 
     argptr = strdup(argptr);
     if(!argptr) {
@@ -1173,6 +1175,16 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
 
     free(argptr);
     break;
+
+  case CURLOPT_MAXCOOKIES:
+    arg = va_arg(param, long);
+    if(arg < 0)
+      break;
+    data->set.maxcookies = arg;
+    if(data->cookies && (!data->share || data->share->cookies != data->cookies))
+      data->cookies->maxcookies = arg;
+    break;
+
 #endif /* CURL_DISABLE_COOKIES */
 
   case CURLOPT_HTTPGET:
diff --git a/lib/urldata.h b/lib/urldata.h
index 55f4884..026e16c 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1584,6 +1584,8 @@ struct UserDefined {
   long tcp_keepintvl;    /* seconds between TCP keepalive probes */
 
   size_t maxconnects;  /* Max idle connections in the connection cache */
+
+  long maxcookies;  /* number of maximam cookies */ 
 };
 
 struct Names {
diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h
index e6611fc..3611647 100644
--- a/src/tool_cfgable.h
+++ b/src/tool_cfgable.h
@@ -205,6 +205,8 @@ struct Configurable {
   bool use_metalink;        /* process given URLs as metalink XML file */
   metalinkfile *metalinkfile_list; /* point to the first node */
   metalinkfile *metalinkfile_last; /* point to the last/current node */
+
+  long max_cookies;          /* number of maximam cookies */
 }; /* struct Configurable */
 
 void free_config_fields(struct Configurable *config);
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index b44b9c0..a2d5b69 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -174,6 +174,7 @@ static const struct LongShort aliases[]= {
   {"$I", "post303",                  FALSE},
   {"$J", "metalink",                 FALSE},
   {"$K", "sasl-ir",                  FALSE},
+  {"$L", "max-cookies",              TRUE},
   {"0",  "http1.0",                  FALSE},
   {"1",  "tlsv1",                    FALSE},
   {"2",  "sslv2",                    FALSE},
@@ -862,6 +863,11 @@ ParameterError getparameter(char *flag,    /* f or -long-flag */
       case 'K': /* --sasl-ir */
         config->sasl_ir = TRUE;
         break;
+      case 'L': /* --max-cookies */
+        err = str2num(&config->max_cookies, nextarg);
+        if(err)
+          return err;
+        break;
       }
       break;
     case '#': /* --progress-bar */
diff --git a/src/tool_help.c b/src/tool_help.c
index 64534ac..b1038fd 100644
--- a/src/tool_help.c
+++ b/src/tool_help.c
@@ -122,6 +122,7 @@ static const char *const helptext[] = {
   "     --mail-from FROM  Mail from this address",
   "     --mail-rcpt TO  Mail to this receiver(s)",
   "     --mail-auth AUTH  Originator address of the original email",
+  "     --max-cookies NUM  Maximum number of cookies",
   "     --max-filesize BYTES  Maximum file size to download (H/F)",
   "     --max-redirs NUM  Maximum number of redirects allowed (H)",
   " -m, --max-time SECONDS  Maximum time allowed for the transfer",
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 3a15bed..11fd973 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -1328,6 +1328,10 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
         retry_sleep_default = (config->retry_delay) ?
           config->retry_delay*1000L : RETRY_SLEEP_DEFAULT; /* ms */
 
+        /* new in 7.3x.0 */
+        if(config->max_cookies)
+          my_setopt(curl, CURLOPT_MAXCOOKIES, config->max_cookies);
+
         retry_numretries = config->req_retry;
         retry_sleep = retry_sleep_default; /* ms */
         retrystart = tvnow();
diff --git a/tests/data/test9000 b/tests/data/test9000
new file mode 100644
index 0000000..2bb795e
--- /dev/null
+++ b/tests/data/test9000
@@ -0,0 +1,71 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+cookies
+cookiejar
+cookie max entries
+</keywords>
+</info>
+# Server-side
+<reply>
+<data>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Length: 4
+Content-Type: text/html
+Funny-head: yesyes
+Set-Cookie: test1value=test1; domain=example.com; path=/;
+Set-Cookie: test2value=test2; domain=example.com; path=/;
+Set-Cookie: test3value=test3; domain=example.com; path=/;
+Set-Cookie: test4value=test4; domain=example.com; path=/;
+Set-Cookie: test5value=test5; domain=example.com; path=/;
+Set-Cookie: test6value=test6; domain=example.com; path=/;
+Set-Cookie: test7value=test7; domain=example.com; path=/;
+Set-Cookie: test8value=test8; domain=example.com; path=/;
+
+boo
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+maximum number of cookies
+ </name>
+<setenv>
+TZ=GMT
+</setenv>
+ <command>
+http://example.com/we/want/9000 --max-cookies 5 -b none -c log/jar9000.txt -x %HOSTIP:%HTTPPORT
+</command>
+</client>
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET http://example.com/we/want/9000 HTTP/1.1
+Host: example.com
+Accept: */*
+Proxy-Connection: Keep-Alive
+
+</protocol>
+<file name="log/jar9000.txt" mode="text">
+# Netscape HTTP Cookie File
+# http://curl.haxx.se/docs/http-cookies.html
+# This file was generated by libcurl! Edit at your own risk.
+
+.example.com	TRUE	/	FALSE	0	test4value	test4
+.example.com	TRUE	/	FALSE	0	test5value	test5
+.example.com	TRUE	/	FALSE	0	test6value	test6
+.example.com	TRUE	/	FALSE	0	test7value	test7
+.example.com	TRUE	/	FALSE	0	test8value	test8
+</file>
+</verify>
+</testcase>
diff --git a/tests/data/test9001 b/tests/data/test9001
new file mode 100644
index 0000000..68cefe6
--- /dev/null
+++ b/tests/data/test9001
@@ -0,0 +1,70 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+cookies
+cookiejar
+delete expired cookies
+</keywords>
+</info>
+# Server-side
+<reply>
+<data>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Length: 4
+Content-Type: text/html
+Funny-head: yesyes
+Set-Cookie: test1value=test1; domain=example.com; path=/;
+Set-Cookie: test2value=test2; expires=Friday, 01-Jan-2038 00:00:00 GMT; domain=example.com; path=/;
+Set-Cookie: test3value=test3; expires=Monday, 13-Jun-1988 03:04:55 GMT; domain=example.com; path=/;
+Set-Cookie: test4value=test4; expires=Friday, 01-Jan-2038 00:00:00 GMT; domain=example.com; path=/;
+Set-Cookie: test5value=test5; expires=Monday, 13-Jun-1988 03:04:55 GMT; domain=example.com; path=/;
+Set-Cookie: test6value=test6; expires=Monday, 13-Jun-1988 03:04:55 GMT; domain=example.com; path=/;
+Set-Cookie: test7value=test7; expires=Friday, 01-Jan-2038 00:00:00 GMT; domain=example.com; path=/;
+Set-Cookie: test8value=test8; expires=Monday, 13-Jun-1988 03:04:55 GMT; domain=example.com; path=/;
+
+boo
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+Delete expired cookies
+ </name>
+<setenv>
+TZ=GMT
+</setenv>
+ <command>
+http://example.com/we/want/9001 -b none -c log/jar9001.txt -x %HOSTIP:%HTTPPORT
+</command>
+</client>
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET http://example.com/we/want/9001 HTTP/1.1
+Host: example.com
+Accept: */*
+Proxy-Connection: Keep-Alive
+
+</protocol>
+<file name="log/jar9001.txt" mode="text">
+# Netscape HTTP Cookie File
+# http://curl.haxx.se/docs/http-cookies.html
+# This file was generated by libcurl! Edit at your own risk.
+
+.example.com	TRUE	/	FALSE	0	test1value	test1
+.example.com	TRUE	/	FALSE	2147483647	test2value	test2
+.example.com	TRUE	/	FALSE	2147483647	test4value	test4
+.example.com	TRUE	/	FALSE	2147483647	test7value	test7
+</file>
+</verify>
+</testcase>
diff --git a/tests/data/test9002 b/tests/data/test9002
new file mode 100644
index 0000000..eb9ed50
--- /dev/null
+++ b/tests/data/test9002
@@ -0,0 +1,107 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+cookies
+shared cookies
+delete old access cookies
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data1>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Type: text/html
+Set-Cookie: test1_1=one_one; domain=foo.com; path=/90020001
+Content-Length: 5
+
+run 1
+</data1>
+<data2>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:01 GMT
+Server: test-server/fake
+Content-Type: text/html
+Set-Cookie: test2_1=two_one; domain=foo.com; path=/9002002
+Set-Cookie: test2_2=two_two; domain=foo.com; path=/9002002
+Content-Length: 5
+
+run 2
+</data2>
+<data3>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:02 GMT
+Server: test-server/fake
+Content-Type: text/html
+Funny-head: yesyes
+Set-Cookie: test3_1=three_one;   domain=foo.com; path=/90020003
+Set-Cookie: test3_2=three_two;   domain=foo.com; path=/90020003
+Set-Cookie: test3_3=three_three; domain=foo.com; path=/90020003
+Set-Cookie: test3_4=three_fore;  domain=foo.com; path=/90020003
+Content-Type: text/html
+Content-Length: 5
+
+run 3
+</data3>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+<name>
+Delete old access cookies
+</name>
+# Explicitly set the time zone to a known good one, in case the user is
+# using one of the 'right' zones that take into account leap seconds
+# which causes the cookie expiry times to be different.
+<setenv>
+TZ=GMT
+</setenv>
+<tool>
+lib9002
+</tool>
+<command>
+http://%HOSTIP:%HTTPPORT/9002 -b none -c log/jar9002.txt
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+GET /90020001 HTTP/1.1
+Accept: */*
+Host: www.host.foo.com
+
+GET /90020002 HTTP/1.1
+Accept: */*
+Host: www.host.foo.com
+
+GET /90020001 HTTP/1.1
+Accept: */*
+Cookie: test1_1=one_one
+Host: www.host.foo.com
+
+GET /90020003 HTTP/1.1
+Accept: */*
+Host: www.host.foo.com
+
+</protocol>
+<file name="log/jar9002.txt" mode="text">
+# Netscape HTTP Cookie File
+# http://curl.haxx.se/docs/http-cookies.html
+# This file was generated by libcurl! Edit at your own risk.
+
+.foo.com	TRUE	/90020001	FALSE	0	test1_1	one_one
+.foo.com	TRUE	/90020003	FALSE	0	test3_1	three_one
+.foo.com	TRUE	/90020003	FALSE	0	test3_2	three_two
+.foo.com	TRUE	/90020003	FALSE	0	test3_3	three_three
+.foo.com	TRUE	/90020003	FALSE	0	test3_4	three_fore
+</file>
+</verify>
+</testcase>
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index 664e000..216bece 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -23,7 +23,8 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect                \
  lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \
  lib1509 lib1510 lib1511 \
  lib1900 \
- lib2033
+ lib2033 \
+ lib9002
 
 chkhostname_SOURCES = chkhostname.c ../../lib/curl_gethostname.c
 chkhostname_LDADD = @CURL_NETWORK_LIBS@
@@ -346,3 +347,6 @@ lib1900_CPPFLAGS = $(AM_CPPFLAGS)
 lib2033_SOURCES = libntlmconnect.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
 lib2033_LDADD = $(TESTUTIL_LIBS)
 lib2033_CPPFLAGS = $(AM_CPPFLAGS) -DUSE_PIPELINING
+
+lib9002_SOURCES = lib9002.c $(SUPPORTFILES)
+lib9002_CPPFLAGS = $(AM_CPPFLAGS)
