]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Merge r1873748 from trunk:
authorJim Jagielski <jim@apache.org>
Tue, 11 Feb 2020 13:19:05 +0000 (13:19 +0000)
committerJim Jagielski <jim@apache.org>
Tue, 11 Feb 2020 13:19:05 +0000 (13:19 +0000)
factor out TE=chunked checking

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

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1873906 13f79535-47bb-0310-9956-ffa450edef68

STATUS
include/ap_mmn.h
include/httpd.h
modules/http/http_filters.c
modules/http/http_protocol.c
server/protocol.c
server/util.c

diff --git a/STATUS b/STATUS
index 4afd862b3856a1176462d00215871a97cc515763..244b8fc2decff2016c7b8b73ceb1e6d2c1f60a66 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -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
index acdf7f1b1ad97821f668093a8512f0fba5c512e9..70300f43308a605d3c771f5b8fb9270c78228380 100644 (file)
  * 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" */
 #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
index 77d42c62a7cff1b026a64b3341d4ac6a66c167eb..4a7b2f40a155c3f87b68305b16bb631b6a009985 100644 (file)
@@ -2495,6 +2495,15 @@ AP_DECLARE(const char *)ap_dir_nofnmatch(ap_dir_match_t *w, const char *fname)
 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
index 5fc44e542f2c07b8e75f8b4e392b2e95f3619db1..d507d1695ed91066f92b89a514d8095f9b2c98aa 100644 (file)
@@ -379,8 +379,7 @@ apr_status_t ap_http_filter(ap_filter_t *f, apr_bucket_brigade *b,
         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) {
index dcafa9c68afde16065f2b1e9687eb7a169d35ed5..e0ed8d50d52278122e212d699ae154d5b626b3cd 100644 (file)
@@ -257,10 +257,9 @@ AP_DECLARE(int) ap_set_keepalive(request_rec *r)
         && (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
index 6864ed0d0a72c219ff2f6c77fa48fad1d775a12f..8e717fb0bd36d60a41f704308f5456533c6dd33d 100644 (file)
@@ -1388,8 +1388,7 @@ request_rec *ap_read_request(conn_rec *conn)
              * 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);
index d1f3c626514843a804cf776c357c5a8509442216..bfc9cf996d70ffe4af53fe3162d23752a2cc6159 100644 (file)
@@ -1708,14 +1708,13 @@ AP_DECLARE(int) ap_find_token(apr_pool_t *p, const char *line, const char *tok)
     }
 }
 
-
-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_pool_t *p, const char *line,
 
     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;
+    }
 
-    return (strncasecmp(&line[lidx], tok, tlen) == 0);
+    s = find_last_token(p, line, "chunked");
+
+    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)