From 2fbdc4ae460b00ac754ca580ac1c0102d4c9e197 Mon Sep 17 00:00:00 2001 From: Andre Malo Date: Sat, 1 Mar 2003 23:57:32 +0000 Subject: [PATCH] Extend mod_negotiation to evaluate the environment variables no-gzip and gzip-only-text/html the same way as mod_deflate does. (it drops all non-identity encodings, not only gzip) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@98871 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 4 +++ modules/mappers/mod_negotiation.c | 51 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/CHANGES b/CHANGES index 559c078738..ce449f3e8a 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,10 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) Extend mod_negotiation to evaluate the environment variables + no-gzip and gzip-only-text/html the same way as mod_deflate does. + [André Malo] + *) Prevent endless loops of internal redirects in mod_rewrite by aborting after exceeding a limit of internal redirects. The limit defaults to 10 and can be changed using the RewriteOptions diff --git a/modules/mappers/mod_negotiation.c b/modules/mappers/mod_negotiation.c index 34336185ce..6f439e757f 100644 --- a/modules/mappers/mod_negotiation.c +++ b/modules/mappers/mod_negotiation.c @@ -101,6 +101,11 @@ typedef struct { #define FLP_DEFAULT FLP_PREFER +/* env evaluation + */ +#define DISCARD_ALL_ENCODINGS 1 /* no-gzip */ +#define DISCARD_ALL_BUT_HTML 2 /* gzip-only-text/html */ + module AP_MODULE_DECLARE_DATA negotiation_module; static void *create_neg_dir_config(apr_pool_t *p, char *dummy) @@ -2226,18 +2231,56 @@ static int variant_has_language(var_rec *variant, const char *lang) return 0; } +/* check for environment variables 'no-gzip' and + * 'gzip-only-text/html' to get a behaviour similiar + * to mod_deflate + */ +static int discard_variant_by_env(var_rec *variant, int discard) +{ + if ( is_identity_encoding(variant->content_encoding) + || !strcmp(variant->content_encoding, "identity")) { + return 0; + } + + return ( (discard == DISCARD_ALL_ENCODINGS) + || (discard == DISCARD_ALL_BUT_HTML + && (!variant->mime_type + || strncmp(variant->mime_type, "text/html", 9)))); +} + static int best_match(negotiation_state *neg, var_rec **pbest) { int j; var_rec *best; float bestq = 0.0f; enum algorithm_results algorithm_result; + int may_discard = 0; var_rec *avail_recs = (var_rec *) neg->avail_vars->elts; + /* fetch request dependent variables + * prefer-language: prefer a certain language. + */ const char *preferred_language = apr_table_get(neg->r->subprocess_env, "prefer-language"); + /* no-gzip: do not send encoded documents */ + if (apr_table_get(neg->r->subprocess_env, "no-gzip")) { + may_discard = DISCARD_ALL_ENCODINGS; + } + + /* gzip-only-text/html: send encoded documents only + * if they are text/html. (no-gzip has a higher priority). + */ + else { + const char *env_value = apr_table_get(neg->r->subprocess_env, + "gzip-only-text/html"); + + if (env_value && !strcmp(env_value, "1")) { + may_discard = DISCARD_ALL_BUT_HTML; + } + } + set_default_lang_quality(neg); /* @@ -2254,6 +2297,14 @@ static int best_match(negotiation_state *neg, var_rec **pbest) for (j = 0; j < neg->avail_vars->nelts; ++j) { var_rec *variant = &avail_recs[j]; + /* if this variant is encoded somehow and there are special + * variables set, we do not negotiate it. see above. + */ + if ( may_discard + && discard_variant_by_env(variant, may_discard)) { + continue; + } + /* if a language is preferred, but the current variant * is not in that language, then drop it for now */ -- 2.40.0