You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2020/02/11 13:19:06 UTC

svn commit: r1873906 - in /httpd/httpd/branches/2.4.x: ./ STATUS include/ap_mmn.h include/httpd.h modules/http/http_filters.c modules/http/http_protocol.c server/protocol.c server/util.c

Author: jim
Date: Tue Feb 11 13:19:05 2020
New Revision: 1873906

URL: http://svn.apache.org/viewvc?rev=1873906&view=rev
Log:
Merge r1873748 from trunk:

factor out TE=chunked checking


Submitted by: covener
Reviewed by: covener, minfrin, jorton

Modified:
    httpd/httpd/branches/2.4.x/   (props changed)
    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_filters.c
    httpd/httpd/branches/2.4.x/modules/http/http_protocol.c
    httpd/httpd/branches/2.4.x/server/protocol.c
    httpd/httpd/branches/2.4.x/server/util.c

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

Modified: httpd/httpd/branches/2.4.x/STATUS
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/STATUS?rev=1873906&r1=1873905&r2=1873906&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/STATUS (original)
+++ httpd/httpd/branches/2.4.x/STATUS Tue Feb 11 13:19:05 2020
@@ -133,12 +133,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
 
-  *) factor out chunked TE checks
-     trunk patch: http://svn.apache.org/r1873748
-     2.4.x patch: http://people.apache.org/~covener/patches/httpd-2.4.x-chunk.diff
-         (MMN conflicts)
-     +1: covener, minfrin, jorton
-
   *) mod_ssl: negotiate the TLS protocol version per name based vhost...
      trunk patch: http://svn.apache.org/r1868645
                   http://svn.apache.org/r1868743

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=1873906&r1=1873905&r2=1873906&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/include/ap_mmn.h (original)
+++ httpd/httpd/branches/2.4.x/include/ap_mmn.h Tue Feb 11 13:19:05 2020
@@ -532,6 +532,7 @@
  * 20120211.89 (2.4.42-dev) Add add dns_pool to proxy_conn_pool and define
  *                          AP_VOLATILIZE_T.
  * 20120211.90 (2.4.42-dev) AP_REG_DEFAULT macro in ap_regex.h
+ * 20120211.91 (2.4.42-dev) Add ap_is_chunked() in httpd.h
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
@@ -539,7 +540,7 @@
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20120211
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 90                  /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 91                  /* 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=1873906&r1=1873905&r2=1873906&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/include/httpd.h (original)
+++ httpd/httpd/branches/2.4.x/include/httpd.h Tue Feb 11 13:19:05 2020
@@ -2495,6 +2495,15 @@ AP_DECLARE(const char *)ap_dir_nofnmatch
 AP_DECLARE(const char *)ap_dir_fnmatch(ap_dir_match_t *w, const char *path,
         const char *fname) __attribute__((nonnull(1,3)));
 
+/**
+ * Determine if the final Transfer-Encoding is "chunked".
+ *
+ * @param p The pool to allocate from
+ * @param line the header field-value to scan
+ * @return 1 if the last Transfer-Encoding is "chunked", else 0
+ */
+AP_DECLARE(int) ap_is_chunked(apr_pool_t *p, const char *line);
+
 #ifdef __cplusplus
 }
 #endif

Modified: httpd/httpd/branches/2.4.x/modules/http/http_filters.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/http/http_filters.c?rev=1873906&r1=1873905&r2=1873906&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/http/http_filters.c (original)
+++ httpd/httpd/branches/2.4.x/modules/http/http_filters.c Tue Feb 11 13:19:05 2020
@@ -379,8 +379,7 @@ apr_status_t ap_http_filter(ap_filter_t
         lenp = apr_table_get(f->r->headers_in, "Content-Length");
 
         if (tenc) {
-            if (strcasecmp(tenc, "chunked") == 0 /* fast path */
-                    || ap_find_last_token(f->r->pool, tenc, "chunked")) {
+            if (ap_is_chunked(f->r->pool, tenc)) {
                 ctx->state = BODY_CHUNK;
             }
             else if (f->r->proxyreq == PROXYREQ_RESPONSE) {

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=1873906&r1=1873905&r2=1873906&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 Feb 11 13:19:05 2020
@@ -257,10 +257,9 @@ AP_DECLARE(int) ap_set_keepalive(request
         && (r->header_only
             || AP_STATUS_IS_HEADER_ONLY(r->status)
             || apr_table_get(r->headers_out, "Content-Length")
-            || ap_find_last_token(r->pool,
+            || ap_is_chunked(r->pool,
                                   apr_table_get(r->headers_out,
-                                                "Transfer-Encoding"),
-                                  "chunked")
+                                                "Transfer-Encoding"))
             || ((r->proto_num >= HTTP_VERSION(1,1))
                 && (r->chunked = 1))) /* THIS CODE IS CORRECT, see above. */
         && r->server->keep_alive

Modified: httpd/httpd/branches/2.4.x/server/protocol.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/server/protocol.c?rev=1873906&r1=1873905&r2=1873906&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/server/protocol.c (original)
+++ httpd/httpd/branches/2.4.x/server/protocol.c Tue Feb 11 13:19:05 2020
@@ -1388,8 +1388,7 @@ request_rec *ap_read_request(conn_rec *c
              * the final encoding ...; the server MUST respond with the 400
              * (Bad Request) status code and then close the connection".
              */
-            if (!(strcasecmp(tenc, "chunked") == 0 /* fast path */
-                    || ap_find_last_token(r->pool, tenc, "chunked"))) {
+            if (!ap_is_chunked(r->pool, tenc)) {
                 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02539)
                               "client sent unknown Transfer-Encoding "
                               "(%s): %s", tenc, r->uri);

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=1873906&r1=1873905&r2=1873906&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/server/util.c (original)
+++ httpd/httpd/branches/2.4.x/server/util.c Tue Feb 11 13:19:05 2020
@@ -1708,14 +1708,13 @@ AP_DECLARE(int) ap_find_token(apr_pool_t
     }
 }
 
-
-AP_DECLARE(int) ap_find_last_token(apr_pool_t *p, const char *line,
-                                   const char *tok)
+static const char *find_last_token(apr_pool_t *p, const char *line,
+                            const char *tok)
 {
     int llen, tlen, lidx;
 
     if (!line)
-        return 0;
+        return NULL;
 
     llen = strlen(line);
     tlen = strlen(tok);
@@ -1723,9 +1722,44 @@ AP_DECLARE(int) ap_find_last_token(apr_p
 
     if (lidx < 0 ||
         (lidx > 0 && !(apr_isspace(line[lidx - 1]) || line[lidx - 1] == ',')))
+        return NULL;
+
+    if (ap_cstr_casecmpn(&line[lidx], tok, tlen) == 0) { 
+        return &line[lidx];
+    }
+   return NULL;
+}
+
+AP_DECLARE(int) ap_find_last_token(apr_pool_t *p, const char *line,
+                                   const char *tok)
+{
+    return find_last_token(p, line, tok) != NULL;
+}
+
+AP_DECLARE(int) ap_is_chunked(apr_pool_t *p, const char *line)
+{
+    const char *s;
+
+    if (!line) 
         return 0;
+    if (!ap_cstr_casecmp(line, "chunked")) { 
+        return 1;
+    }
+
+    s = find_last_token(p, line, "chunked");
 
-    return (strncasecmp(&line[lidx], tok, tlen) == 0);
+    if (!s) return 0;
+ 
+    /* eat spaces right-to-left to see what precedes "chunked" */
+    while (--s > line) { 
+        if (*s != ' ') break;
+    }
+
+    /* found delim, or leading ws (input wasn't parsed by httpd as a header) */
+    if (*s == ',' || *s == ' ') { 
+        return 1;
+    }
+    return 0;
 }
 
 AP_DECLARE(char *) ap_escape_shell_cmd(apr_pool_t *p, const char *str)