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.

TIA, nd
-- 
s;.*;aaaaaoaaaoaaaaooooaaoaaaomaaaa:a:alataa:aaoat:a:a:a
maoaa:a:laoata:a:oia:a:o:a:m:a:o:alaoooat:aaool:aaoaa
matooololaaatoto:aaa:o:a:o:m;;s:\s:\::g;y;mailto:;
\40\51/\134\137|ndparker <[EMAIL PROTECTED]>;;print;

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   13 Nov 2002 20:33:37 -0000
@@ -897,6 +897,66 @@
     return cp;
 }
 
+/* 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"));
+}
+
+/* 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 = !!apr_table_get(r->subprocess_env, "no-gzip");
+    int discard_nonhtml = 0;
+
+    int is_identity = 1;
+
+    /* don't bother */
+    if (!encoding) {
+        return 0;
+    }
+
+    if (!discard_all) {
+        char *env_value = (char *) apr_table_get(r->subprocess_env,
+                                                 "gzip-only-text/html");
+        discard_nonhtml = (env_value && !strcmp(env_value, "1"));
+
+        if (!discard_nonhtml) {
+            return 0;
+        }
+    }
+
+    while (*encoding) {
+        encoding = (char *) get_entry(neg->pool, &current, encoding);
+
+        if (!is_identity_encoding(current.name) &&
+             strcmp(current.name, "identity")) {
+            is_identity = 0;
+            break;
+        }
+    }
+
+    if (!is_identity     &&
+        (discard_all     ||
+        (discard_nonhtml && (!type || strncmp(type, "text/html", 9))))) {
+        return 1;
+    }
+
+    return 0;
+}
+
 static int read_type_map(apr_file_t **map, negotiation_state *neg, request_rec *rr)
 {
     request_rec *r = neg->r;
@@ -988,7 +1048,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 +1265,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 +1926,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