]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Merge r1868313 from trunk:
authorYann Ylavic <ylavic@apache.org>
Thu, 7 Nov 2019 12:21:35 +0000 (12:21 +0000)
committerYann Ylavic <ylavic@apache.org>
Thu, 7 Nov 2019 12:21:35 +0000 (12:21 +0000)
Honor "Accept-Encoding: foo;q=0" as per RFC 7231; which means 'foo' is
"not acceptable".  PR 58158

Submitted by: jailletc36
Reviewed/backported by: jailletc36, jim, ylavic

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

CHANGES
modules/filters/mod_brotli.c
modules/filters/mod_deflate.c

diff --git a/CHANGES b/CHANGES
index d2e959c1bacaf8bb6267129678e9d4b12a1636f7..6fd82fbe0084053746e19b76bad332169a2e0c2a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.4.42
    
+  *) mod_deflate, mod_brotli: honor "Accept-Encoding: foo;q=0" as per RFC 7231; which
+     means 'foo' is "not acceptable".  PR 58158 [Chistophe Jaillet]
+
   *) mod_md v2.2.3: 
      - Configuring MDCAChallenges replaces any previous existing challenge configuration. It
        had been additive before which was not the intended behaviour. [@mkauf]
index 56717e7b8d4ba8ba5f5c6d8b7f311de9e16d837f..d1d7044ac8f3b697f629c4788923ccacd506b317 100644 (file)
@@ -344,6 +344,7 @@ static apr_status_t compress_filter(ap_filter_t *f, apr_bucket_brigade *bb)
         const char *encoding;
         const char *token;
         const char *accepts;
+        const char *q = NULL;
 
         /* Only work on main request, not subrequests, that are not
          * a 204 response with no content, and are not tagged with the
@@ -411,7 +412,19 @@ static apr_status_t compress_filter(ap_filter_t *f, apr_bucket_brigade *bb)
             token = (*accepts) ? ap_get_token(r->pool, &accepts, 0) : NULL;
         }
 
-        if (!token || token[0] == '\0') {
+        /* Find the qvalue, if provided */
+        if (*accepts) {
+            while (*accepts == ';') {
+                ++accepts;
+            }
+            q = ap_get_token(r->pool, &accepts, 1);
+            ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
+                          "token: '%s' - q: '%s'", token, q);
+        }
+
+        /* No acceptable token found or q=0 */
+        if (!token || token[0] == '\0' ||
+            (q && strlen(q) >= 3 && strncmp("q=0.000", q, strlen(q)) == 0)) {
             ap_remove_output_filter(f);
             return ap_pass_brigade(f->next, bb);
         }
index e714ca68c8e0d5564da0fcba6f23363a8b296b4a..b079709a26c0467f31a878c4ca2354e624ef1292 100644 (file)
@@ -699,6 +699,8 @@ static apr_status_t deflate_out_filter(ap_filter_t *f,
          */
         if (!apr_table_get(r->subprocess_env, "force-gzip")) {
             const char *accepts;
+            const char *q = NULL;
+
             /* if they don't have the line, then they can't play */
             accepts = apr_table_get(r->headers_in, "Accept-Encoding");
             if (accepts == NULL) {
@@ -721,10 +723,21 @@ static apr_status_t deflate_out_filter(ap_filter_t *f,
                 token = (*accepts) ? ap_get_token(r->pool, &accepts, 0) : NULL;
             }
 
-            /* No acceptable token found. */
-            if (token == NULL || token[0] == '\0') {
+            /* Find the qvalue, if provided */
+            if (*accepts) {
+                while (*accepts == ';') {
+                    ++accepts;
+                }
+                q = ap_get_token(r->pool, &accepts, 1);
+                ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
+                              "token: '%s' - q: '%s'", token, q);
+            }
+
+            /* No acceptable token found or q=0 */
+            if (!token || token[0] == '\0' ||
+                (q && strlen(q) >= 3 && strncmp("q=0.000", q, strlen(q)) == 0)) {
                 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
-                              "Not compressing (no Accept-Encoding: gzip)");
+                              "Not compressing (no Accept-Encoding: gzip or q=0)");
                 ap_remove_output_filter(f);
                 return ap_pass_brigade(f->next, bb);
             }