You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by re...@apache.org on 2003/09/29 23:09:47 UTC

cvs commit: httpd-2.0/modules/experimental cache_util.c

rederpj     2003/09/29 14:09:47

  Modified:    .        Tag: APACHE_2_0_BRANCH CHANGES STATUS
               modules/experimental Tag: APACHE_2_0_BRANCH cache_util.c
  Log:
    *) cache_util: Fix ap_check_cache_feshness to check max_age, smax_age, and
       expires as directed in RFC 2616. [Thomas Castelle tcastelle@generali.fr]
  
  Reviewed by: Paul J. Reder, Bill Stoddard, and Roy T. Fielding,
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.988.2.164 +3 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.988.2.163
  retrieving revision 1.988.2.164
  diff -u -r1.988.2.163 -r1.988.2.164
  --- CHANGES	29 Sep 2003 12:12:15 -0000	1.988.2.163
  +++ CHANGES	29 Sep 2003 21:09:46 -0000	1.988.2.164
  @@ -1,5 +1,8 @@
   Changes with Apache 2.0.48
   
  +  *) cache_util: Fix ap_check_cache_feshness to check max_age, smax_age, and
  +     expires as directed in RFC 2616. [Thomas Castelle tcastelle@generali.fr]
  +
     *) Ensure that ssl-std.conf is generated at configure time, and switch
        to using the expanded config variables to work the same as 
        httpd-std.conf PR: 1961
  
  
  
  1.751.2.490 +1 -6      httpd-2.0/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/STATUS,v
  retrieving revision 1.751.2.489
  retrieving revision 1.751.2.490
  diff -u -r1.751.2.489 -r1.751.2.490
  --- STATUS	29 Sep 2003 12:08:06 -0000	1.751.2.489
  +++ STATUS	29 Sep 2003 21:09:46 -0000	1.751.2.490
  @@ -78,11 +78,6 @@
         http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/experimental/mod_mem_cache.c.diff?r1=1.93&r2=1.94
         +1: rederpj, fielding, trawick
   
  -    * Correct the code in ap_check_cache_feshness to check max_age, smax_age,
  -      and expires correctly. This is a RFC 2616 compliance issue.
  -      http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/experimental/cache_util.c.diff?r1=1.26&r2=1.27
  -      +1: rederpj, stoddard, fielding
  -
       * mod_rewrite.c: Fix mod_rewrite's support of the [P] option to send
         rewritten request using "proxy:". The code was adding multiple "proxy:"
         fields in the rewritten URI. PR: 13946.
  
  
  
  No                   revision
  No                   revision
  1.23.2.2  +42 -16    httpd-2.0/modules/experimental/cache_util.c
  
  Index: cache_util.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/experimental/cache_util.c,v
  retrieving revision 1.23.2.1
  retrieving revision 1.23.2.2
  diff -u -r1.23.2.1 -r1.23.2.2
  --- cache_util.c	3 Feb 2003 17:31:36 -0000	1.23.2.1
  +++ cache_util.c	29 Sep 2003 21:09:47 -0000	1.23.2.2
  @@ -162,7 +162,8 @@
                                               request_rec *r)
   {
       apr_int64_t age, maxage_req, maxage_cresp, maxage, smaxage, maxstale, minfresh;
  -    const char *cc_cresp, *cc_req, *pragma_cresp;
  +    int age_in_errhdr = 0;
  +    const char *cc_cresp, *cc_ceresp, *cc_req;
       const char *agestr = NULL;
       char *val;
       apr_time_t age_c = 0;
  @@ -201,12 +202,16 @@
        * 
        */
       cc_cresp = apr_table_get(r->headers_out, "Cache-Control");
  +    cc_ceresp = apr_table_get(r->err_headers_out, "Cache-Control");
       cc_req = apr_table_get(r->headers_in, "Cache-Control");
  -    /* TODO: pragma_cresp not being used? */
  -    pragma_cresp = apr_table_get(r->headers_out, "Pragma");  
  +    
       if ((agestr = apr_table_get(r->headers_out, "Age"))) {
           age_c = apr_atoi64(agestr);
       }
  +    else if ((agestr = apr_table_get(r->err_headers_out, "Age"))) {
  +        age_c = apr_atoi64(agestr);
  +        age_in_errhdr = 1;
  +    }
   
       /* calculate age of object */
       age = ap_cache_current_age(info, age_c, r->request_time);
  @@ -214,6 +219,9 @@
       /* extract s-maxage */
       if (cc_cresp && ap_cache_liststr(r->pool, cc_cresp, "s-maxage", &val))
           smaxage = apr_atoi64(val);
  +    else if (cc_ceresp && ap_cache_liststr(r->pool, cc_ceresp, "s-maxage", &val)) {
  +        smaxage = apr_atoi64(val);
  +    }
       else
           smaxage = -1;
   
  @@ -226,6 +234,9 @@
       /* extract max-age from response */
       if (cc_cresp && ap_cache_liststr(r->pool, cc_cresp, "max-age", &val))
           maxage_cresp = apr_atoi64(val);
  +    else if (cc_ceresp && ap_cache_liststr(r->pool, cc_ceresp, "max-age", &val)) {
  +        maxage_cresp = apr_atoi64(val);
  +    }
       else
           maxage_cresp = -1;
   
  @@ -253,29 +264,44 @@
   
       /* override maxstale if must-revalidate or proxy-revalidate */
       if (maxstale && ((cc_cresp &&
  -                      ap_cache_liststr(NULL,
  -                                       cc_cresp, "must-revalidate", NULL))
  -                     || (cc_cresp && ap_cache_liststr(NULL,
  -                                                      cc_cresp,
  -                                                      "proxy-revalidate", NULL))))
  +                      ap_cache_liststr(NULL, cc_cresp,
  +                                       "must-revalidate", NULL)) ||
  +                     (cc_cresp &&
  +                      ap_cache_liststr(NULL, cc_cresp,
  +                                       "proxy-revalidate", NULL)) ||
  +                     (cc_ceresp &&
  +                      ap_cache_liststr(NULL, cc_ceresp,
  +                                       "must-revalidate", NULL)) ||
  +                     (cc_ceresp &&
  +                      ap_cache_liststr(NULL, cc_ceresp,
  +                                       "proxy-revalidate", NULL)))) {
           maxstale = 0;
  +    }
       /* handle expiration */
  -    if ((-1 < smaxage && age < (smaxage - minfresh)) ||
  -        (-1 < maxage && age < (maxage + maxstale - minfresh)) ||
  -        (info->expire != APR_DATE_BAD && age < (apr_time_sec(info->expire - info->date) + maxstale - minfresh))) {
  +    if (((smaxage != -1) && (age < (smaxage - minfresh))) ||
  +        ((maxage != -1) && (age < (maxage + maxstale - minfresh))) ||
  +        ((smaxage == -1) && (maxage == -1) &&
  +         (info->expire != APR_DATE_BAD) &&
  +         (age < (apr_time_sec(info->expire - info->date) + maxstale - minfresh)))) {
           /* it's fresh darlings... */
           /* set age header on response */
  -        apr_table_set(r->headers_out, "Age",
  -                      apr_psprintf(r->pool, "%lu", (unsigned long)age));
  +        if (age_in_errhdr) {
  +            apr_table_set(r->err_headers_out, "Age",
  +                          apr_psprintf(r->pool, "%lu", (unsigned long)age));
  +        }
  +        else {
  +            apr_table_set(r->headers_out, "Age",
  +                          apr_psprintf(r->pool, "%lu", (unsigned long)age));
  +        }
   
           /* add warning if maxstale overrode freshness calculation */
  -        if (!((-1 < smaxage && age < smaxage) ||
  -              (-1 < maxage && age < maxage) ||
  +        if (!(((smaxage != -1) && age < smaxage) ||
  +              ((maxage != -1) && age < maxage) ||
                 (info->expire != APR_DATE_BAD && (info->expire - info->date) > age))) {
               /* make sure we don't stomp on a previous warning */
               apr_table_merge(r->headers_out, "Warning", "110 Response is stale");
           }
  -        return 1;    /* Cache object is fresh */
  +        return 1;    /* Cache object is fresh (enough) */
       }
       return 0;        /* Cache object is stale */
   }