From: carson@lehman.com
Date: Tue, 26 Mar 1996 21:08:36 -0500
Message-Id: <199603270208.VAA14687@dragon.lehman.com>
To: wessels@colorado.edu
Subject: Diffs to fix caching problems in cached-1.4.pl3
Reply-To: carson@lehman.com


Here are my diffs that fix cached's over-active caching (diffed against
cached-1.4.pl3).

*** cached-1.4.pl3/src/server/ttl.c     Mon Mar  4 14:46:33 1996
--- cached-1.4.pl3.LB1/src/server/ttl.c Tue Mar 26 21:02:30 1996
***************
*** 183,188 ****
--- 183,189 ----
  
      debug(5, "ttlSet: Choosing TTL for %s\n", entry->url);
  
+ #if 0
      /*
       * Check for Unauthorized HTTP requests.
       * This needs to be improved.  I don't think we can/should rely on
***************
*** 193,201 ****
--- 194,209 ----
        return 0;
      if (storeGrep(entry, "407", 15))  /* NS: Proxy Authentication Required
*/
        return 0;
+ #endif
  
      /* these are case-insensitive compares */
      buf[0] = '\0';
+     if (storeMatchMime(entry, "pragma: ", buf, 300)) {
+       if (strstr(buf, "no-cache")) {
+       debug(10, "pragma: no-cache found\n");
+       return(0);
+       }
+     }
      if (storeMatchMime(entry, "last-modified: ", buf, 300)) {
        if ((x = parse_rfc850(buf)) >= 0) {
            last_modified = x;
***************
*** 223,228 ****
--- 231,279 ----
      if (their_date > 0)
        debug(5, "ttlSet:   Server-Date: %s\n", mkrfc850(&their_date));
  
+     {    
+       mem_ptr mem;
+       mem_node p;
+       int http_code;
+       char http_resp[16];
+       
+       /*
+        * I'm going to assume that the len is at least enough for
+        * <nl>HTTP/1.n nnn
+        */
+       
+       if (entry
+           && (mem = store_mem_obj(entry, data))
+           && (p = mem->head)
+           && (p->len >= 16)) {
+           strncpy(http_resp, p->data, 16);
+           http_resp[15] = 0;
+           if (sscanf(http_resp, "HTTP/%*d.%*d %d", &http_code) < 1) {
+               debug(0, "Couldn't parse HTTP response \"%s\" in ttlSet!\n",
+                     http_resp);
+               return(0);
+           }
+           debug(10, "ttlSet: http_code=%d\n", http_code);
+           switch(http_code) {
+           case 200:
+           case 203:
+           case 300:
+           case 301:
+           case 410:
+               /* cachable - do nothing */
+               break;
+           case 302:
+               if (flags & TTL_EXPIRES)
+                   break;
+           default:
+               return(0);
+           }
+       } else {        
+           debug(0, "Couldn't parse HTTP response in ttlSet!\n");
+           return(0);
+       }
+     }
+     
      now = their_date > 0 ? their_date : cached_curtime;
  
      if (expire > 0) {

