Honor "Accept-Encoding: foo;q=0" as per RFC 7231; which means 'foo' is "not acceptabl...
authorChristophe Jaillet <jailletc36@apache.org>
Fri, 11 Oct 2019 20:21:14 +0000 (20:21 +0000)
committerChristophe Jaillet <jailletc36@apache.org>
Fri, 11 Oct 2019 20:21:14 +0000 (20:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1868313 13f79535-47bb-0310-9956-ffa450edef68

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

diff --git a/CHANGES b/CHANGES
index 1bf06ed97936299713d522a8621289abeb3a08fd..793d6388dbf1375203ba3683c336d1cb4acf02f3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.1
 
+  *) 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_proxy: Fix crash by resolving pool concurrency problems. PR 63503
      [Ruediger Pluem, Eric Covener]
 
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 3948a76254a32e4f841063da5d81df3a30b17554..9ce104af27c532641a2e97b043ac67a99c5f744d 100644 (file)
@@ -739,6 +739,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) {
@@ -761,10 +763,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);
             }