httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1487123 - in /httpd/httpd/branches/2.4.x: ./ CHANGES STATUS include/ap_mmn.h include/httpd.h modules/http/http_protocol.c server/util.c
Date Tue, 28 May 2013 21:17:53 GMT
Author: minfrin
Date: Tue May 28 21:17:53 2013
New Revision: 1487123

URL: http://svn.apache.org/r1487123
Log:
core: Add the ability to do explicit matching on weak and strong ETags
as per RFC2616 Section 13.3.3.

trunk patch: http://svn.apache.org/r1479528

Submitted by: minfrin
Reviewed by: jim, wrowe

Modified:
    httpd/httpd/branches/2.4.x/   (props changed)
    httpd/httpd/branches/2.4.x/CHANGES
    httpd/httpd/branches/2.4.x/STATUS
    httpd/httpd/branches/2.4.x/include/ap_mmn.h
    httpd/httpd/branches/2.4.x/include/httpd.h
    httpd/httpd/branches/2.4.x/modules/http/http_protocol.c
    httpd/httpd/branches/2.4.x/server/util.c

Propchange: httpd/httpd/branches/2.4.x/
------------------------------------------------------------------------------
  Merged /httpd/httpd/trunk:r1479528

Modified: httpd/httpd/branches/2.4.x/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/CHANGES?rev=1487123&r1=1487122&r2=1487123&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/CHANGES [utf-8] (original)
+++ httpd/httpd/branches/2.4.x/CHANGES [utf-8] Tue May 28 21:17:53 2013
@@ -2,6 +2,10 @@
 
 Changes with Apache 2.4.5
 
+  *) core: Add the ability to do explicit matching on weak and strong ETags
+     as per RFC2616 Section 13.3.3. [Graham Leggett, Co-Advisor
+     <coad measurement-factory.com>]
+
   *) mod_cache: Ensure that updated responses to HEAD requests don't get
      mistakenly paired with a previously cached body. Ensure that any existing
      body is removed when a HEAD request is cached. [Graham Leggett,

Modified: httpd/httpd/branches/2.4.x/STATUS
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/STATUS?rev=1487123&r1=1487122&r2=1487123&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/STATUS (original)
+++ httpd/httpd/branches/2.4.x/STATUS Tue May 28 21:17:53 2013
@@ -90,12 +90,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
  
-    * core: Add the ability to do explicit matching on weak and strong ETags
-      as per RFC2616 Section 13.3.3.
-      trunk patch: http://svn.apache.org/r1479528
-      2.4.x patch: trunk patch works (minus CHANGES, mmn bump)
-      +1: minfrin, jim, wrowe
-
     * core, mod_cache: Ensure RFC2616 compliance in ap_meets_conditions()
       with weak validation combined with If-Range and Range headers. Break
       out explicit conditional header checks to be useable elsewhere in the

Modified: httpd/httpd/branches/2.4.x/include/ap_mmn.h
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/include/ap_mmn.h?rev=1487123&r1=1487122&r2=1487123&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/include/ap_mmn.h (original)
+++ httpd/httpd/branches/2.4.x/include/ap_mmn.h Tue May 28 21:17:53 2013
@@ -406,6 +406,7 @@
  * 20120211.14 (2.4.5-dev) Add ppinherit and inherit to proxy_server_conf
  * 20120211.15 (2.4.5-dev) Add dav_join_error()
  * 20120211.16 (2.4.5-dev) Add cache_control_t.invalidated
+ * 20120211.17 (2.5.0-dev) Add ap_find_etag_weak(), ap_find_etag_strong()
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
@@ -413,7 +414,7 @@
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20120211
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 16                   /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 17                   /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a

Modified: httpd/httpd/branches/2.4.x/include/httpd.h
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/include/httpd.h?rev=1487123&r1=1487122&r2=1487123&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/include/httpd.h (original)
+++ httpd/httpd/branches/2.4.x/include/httpd.h Tue May 28 21:17:53 2013
@@ -1510,6 +1510,24 @@ AP_DECLARE(char *) ap_get_list_item(apr_
 AP_DECLARE(int) ap_find_list_item(apr_pool_t *p, const char *line, const char *tok);
 
 /**
+ * Do a weak ETag comparison within an HTTP field value list.
+ * @param p The pool to allocate from
+ * @param line The field value list to search
+ * @param tok The token to search for
+ * @return 1 if found, 0 if not found.
+ */
+AP_DECLARE(int) ap_find_etag_weak(apr_pool_t *p, const char *line, const char *tok);
+
+/**
+ * Do a strong ETag comparison within an HTTP field value list.
+ * @param p The pool to allocate from
+ * @param line The field value list to search
+ * @param tok The token to search for
+ * @return 1 if found, 0 if not found.
+ */
+AP_DECLARE(int) ap_find_etag_strong(apr_pool_t *p, const char *line, const char *tok);
+
+/**
  * Retrieve a token, spacing over it and adjusting the pointer to
  * the first non-white byte afterwards.  Note that these tokens
  * are delimited by semis and commas and can also be delimited

Modified: httpd/httpd/branches/2.4.x/modules/http/http_protocol.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/http/http_protocol.c?rev=1487123&r1=1487122&r2=1487123&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/http/http_protocol.c (original)
+++ httpd/httpd/branches/2.4.x/modules/http/http_protocol.c Tue May 28 21:17:53 2013
@@ -345,8 +345,8 @@ AP_DECLARE(int) ap_meets_conditions(requ
      */
     if ((if_match = apr_table_get(r->headers_in, "If-Match")) != NULL) {
         if (if_match[0] != '*'
-            && (etag == NULL || etag[0] == 'W'
-                || !ap_find_list_item(r->pool, if_match, etag))) {
+                && (etag == NULL
+                        || !ap_find_etag_strong(r->pool, if_match, etag))) {
             return HTTP_PRECONDITION_FAILED;
         }
     }
@@ -386,19 +386,18 @@ AP_DECLARE(int) ap_meets_conditions(requ
             }
             else if (etag != NULL) {
                 if (apr_table_get(r->headers_in, "Range")) {
-                    not_modified = etag[0] != 'W'
-                                   && ap_find_list_item(r->pool,
-                                                        if_nonematch, etag);
+                    not_modified = ap_find_etag_strong(r->pool, if_nonematch,
+                            etag);
                 }
                 else {
-                    not_modified = ap_find_list_item(r->pool,
-                                                     if_nonematch, etag);
+                    not_modified = ap_find_etag_weak(r->pool, if_nonematch,
+                            etag);
                 }
             }
         }
         else if (if_nonematch[0] == '*'
-                 || (etag != NULL
-                     && ap_find_list_item(r->pool, if_nonematch, etag))) {
+                || (etag != NULL
+                        && ap_find_etag_strong(r->pool, if_nonematch, etag)))
{
             return HTTP_PRECONDITION_FAILED;
         }
     }

Modified: httpd/httpd/branches/2.4.x/server/util.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/server/util.c?rev=1487123&r1=1487122&r2=1487123&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/server/util.c (original)
+++ httpd/httpd/branches/2.4.x/server/util.c Tue May 28 21:17:53 2013
@@ -1286,27 +1286,58 @@ AP_DECLARE(char *) ap_get_list_item(apr_
     return token;
 }
 
+typedef enum ap_etag_e {
+    AP_ETAG_NONE,
+    AP_ETAG_WEAK,
+    AP_ETAG_STRONG
+} ap_etag_e;
+
 /* Find an item in canonical form (lowercase, no extra spaces) within
  * an HTTP field value list.  Returns 1 if found, 0 if not found.
  * This would be much more efficient if we stored header fields as
  * an array of list items as they are received instead of a plain string.
  */
-AP_DECLARE(int) ap_find_list_item(apr_pool_t *p, const char *line,
-                                  const char *tok)
+static int find_list_item(apr_pool_t *p, const char *line,
+                                  const char *tok, ap_etag_e type)
 {
     const unsigned char *pos;
     const unsigned char *ptr = (const unsigned char *)line;
     int good = 0, addspace = 0, in_qpair = 0, in_qstr = 0, in_com = 0;
 
-    if (!line || !tok)
+    if (!line || !tok) {
+        return 0;
+    }
+    if (type == AP_ETAG_STRONG && *tok != '\"') {
         return 0;
+    }
+    if (type == AP_ETAG_WEAK) {
+        if (*tok == 'W' && (*(tok+1)) == '/' && (*(tok+2)) == '\"') {
+            tok += 2;
+        }
+        else if (*tok != '\"') {
+            return 0;
+        }
+    }
 
     do {  /* loop for each item in line's list */
 
         /* Find first non-comma, non-whitespace byte */
-
-        while (*ptr == ',' || apr_isspace(*ptr))
+        while (*ptr == ',' || apr_isspace(*ptr)) {
             ++ptr;
+        }
+
+        /* Account for strong or weak Etags, depending on our search */
+        if (type == AP_ETAG_STRONG && *ptr != '\"') {
+            break;
+        }
+        if (type == AP_ETAG_WEAK) {
+            if (*ptr == 'W' && (*(ptr+1)) == '/' && (*(ptr+2)) == '\"') {
+                ptr += 2;
+            }
+            else if (*ptr != '\"') {
+                break;
+            }
+        }
 
         if (*ptr)
             good = 1;  /* until proven otherwise for this item */
@@ -1374,7 +1405,8 @@ AP_DECLARE(int) ap_find_list_item(apr_po
                                if (in_com || in_qstr)
                                    good = good && (*pos++ == *ptr);
                                else
-                                   good = good && (*pos++ == apr_tolower(*ptr));
+                                   good = good
+                                       && (apr_tolower(*pos++) == apr_tolower(*ptr));
                                addspace = 0;
                                break;
                 }
@@ -1388,6 +1420,34 @@ AP_DECLARE(int) ap_find_list_item(apr_po
     return good;
 }
 
+/* Find an item in canonical form (lowercase, no extra spaces) within
+ * an HTTP field value list.  Returns 1 if found, 0 if not found.
+ * This would be much more efficient if we stored header fields as
+ * an array of list items as they are received instead of a plain string.
+ */
+AP_DECLARE(int) ap_find_list_item(apr_pool_t *p, const char *line,
+                                  const char *tok)
+{
+    return find_list_item(p, line, tok, AP_ETAG_NONE);
+}
+
+/* Find a strong Etag in canonical form (lowercase, no extra spaces) within
+ * an HTTP field value list.  Returns 1 if found, 0 if not found.
+ */
+AP_DECLARE(int) ap_find_etag_strong(apr_pool_t *p, const char *line,
+                                    const char *tok)
+{
+    return find_list_item(p, line, tok, AP_ETAG_STRONG);
+}
+
+/* Find a weak ETag in canonical form (lowercase, no extra spaces) within
+ * an HTTP field value list.  Returns 1 if found, 0 if not found.
+ */
+AP_DECLARE(int) ap_find_etag_weak(apr_pool_t *p, const char *line,
+                                  const char *tok)
+{
+    return find_list_item(p, line, tok, AP_ETAG_WEAK);
+}
 
 /* Retrieve a token, spacing over it and returning a pointer to
  * the first non-white byte afterwards.  Note that these tokens



Mime
View raw message