* Andr� Malo wrote:

> since mod_negotiation is also able to deliver (statically) compressed
> content by request, it should respect the 'no-gzip' and
> 'gzip-only-text/html' variables, too.
> 
> The attached patch adds this feature to mod_negotiation. It actually drops
> all encodings that are not identity, not only 'gzip'. But I think, this is
> probably the desired behaviour (should it be configurable?).
> 
> I'm not sure, if it's all correct styled etc. but it works for me :)
> Please point me to the right direction if there's something wrong.

however, I optimized and shortened it a little bit (new patch attached).

nd
-- 
print "Just Another Perl Hacker";

# Andr� Malo, <http://www.perlig.de/> #
Index: mod_negotiation.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/mappers/mod_negotiation.c,v
retrieving revision 1.107
diff -u -r1.107 mod_negotiation.c
--- mod_negotiation.c   9 Aug 2002 19:21:57 -0000       1.107
+++ mod_negotiation.c   14 Nov 2002 16:32:15 -0000
@@ -897,6 +897,60 @@
     return cp;
 }
 
+/* is_identity_encoding is included for back-compat, but does anyone
+ * use 7bit, 8bit or binary in their var files??
+ */
+
+static int is_identity_encoding(const char *enc)
+{
+    return (!enc || !enc[0] || !strcmp(enc, "7bit") || !strcmp(enc, "8bit")
+            || !strcmp(enc, "binary"));
+}
+
+/* check for environment variables 'no-gzip' and
+ * 'gzip-only-text/html' to get a behaviour similiar
+ * to mod_deflate
+ */
+
+static int discard_by_encoding(negotiation_state *neg, const char *encoding,
+                               const char *type)
+{
+    request_rec *r = neg->r;
+    accept_rec current;
+
+    int discard_all, discard_nonhtml;
+    int is_identity = 1;
+
+    /* don't bother */
+    if (!encoding) {
+        return 0;
+    }
+
+    if (!(discard_all = !!apr_table_get(r->subprocess_env, "no-gzip"))) {
+        const char *env_value = apr_table_get(r->subprocess_env,
+                                              "gzip-only-text/html");
+
+        if (!(discard_nonhtml = (env_value && !strcmp(env_value, "1")))) {
+            return 0;
+        }
+    }
+
+    while (*encoding) {
+        encoding = get_entry(neg->pool, &current, encoding);
+
+        if (!is_identity_encoding(current.name) &&
+             strcmp(current.name, "identity")) {
+            is_identity = 0;
+            break;
+        }
+    }
+
+    return (!is_identity &&
+            (discard_all ||
+             (discard_nonhtml && 
+              (!type || strncmp(type, "text/html", 9)))));
+}
+
 static int read_type_map(apr_file_t **map, negotiation_state *neg, request_rec *rr)
 {
     request_rec *r = neg->r;
@@ -988,7 +1042,9 @@
             }
         }
         else {
-            if (*mime_info.file_name && has_content) {
+            if (*mime_info.file_name && has_content &&
+                !discard_by_encoding(neg, mime_info.content_encoding,
+                                     mime_info.mime_type)) {
                 void *new_var = apr_array_push(neg->avail_vars);
 
                 memcpy(new_var, (void *) &mime_info, sizeof(var_rec));
@@ -1203,6 +1259,12 @@
             return read_type_map(NULL, neg, sub_req);
         }
 
+        if (discard_by_encoding(neg, sub_req->content_encoding,
+                                sub_req->content_type)) {
+            ap_destroy_sub_req(sub_req);
+            continue;
+        }
+
         /* Have reasonable variant --- gather notes. */
 
         mime_info.sub_req = sub_req;
@@ -1858,17 +1920,6 @@
     else {
         variant->charset_quality = 0.0f;
     }
-}
-
-
-/* is_identity_encoding is included for back-compat, but does anyone
- * use 7bit, 8bin or binary in their var files??
- */
-
-static int is_identity_encoding(const char *enc)
-{
-    return (!enc || !enc[0] || !strcmp(enc, "7bit") || !strcmp(enc, "8bit")
-            || !strcmp(enc, "binary"));
 }
 
 /*

Reply via email to