| 2269 | } |
| 2270 | |
| 2271 | static int best_match(negotiation_state *neg, var_rec **pbest) |
| 2272 | { |
| 2273 | int j; |
| 2274 | var_rec *best; |
| 2275 | float bestq = 0.0f; |
| 2276 | enum algorithm_results algorithm_result; |
| 2277 | int may_discard = 0; |
| 2278 | |
| 2279 | var_rec *avail_recs = (var_rec *) neg->avail_vars->elts; |
| 2280 | |
| 2281 | /* fetch request dependent variables |
| 2282 | * prefer-language: prefer a certain language. |
| 2283 | */ |
| 2284 | const char *preferred_language = apr_table_get(neg->r->subprocess_env, |
| 2285 | "prefer-language"); |
| 2286 | |
| 2287 | /* no-gzip: do not send encoded documents */ |
| 2288 | if (apr_table_get(neg->r->subprocess_env, "no-gzip")) { |
| 2289 | may_discard = DISCARD_ALL_ENCODINGS; |
| 2290 | } |
| 2291 | |
| 2292 | /* gzip-only-text/html: send encoded documents only |
| 2293 | * if they are text/html. (no-gzip has a higher priority). |
| 2294 | */ |
| 2295 | else { |
| 2296 | const char *env_value = apr_table_get(neg->r->subprocess_env, |
| 2297 | "gzip-only-text/html"); |
| 2298 | |
| 2299 | if (env_value && !strcmp(env_value, "1")) { |
| 2300 | may_discard = DISCARD_ALL_BUT_HTML; |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | set_default_lang_quality(neg); |
| 2305 | |
| 2306 | /* |
| 2307 | * Find the 'best' variant |
| 2308 | * We run the loop possibly twice: if "prefer-language" |
| 2309 | * environment variable is set but we did not find an appropriate |
| 2310 | * best variant. In that case forget the preferred language and |
| 2311 | * negotiate over all variants. |
| 2312 | */ |
| 2313 | |
| 2314 | do { |
| 2315 | best = NULL; |
| 2316 | |
| 2317 | for (j = 0; j < neg->avail_vars->nelts; ++j) { |
| 2318 | var_rec *variant = &avail_recs[j]; |
| 2319 | |
| 2320 | /* if this variant is encoded somehow and there are special |
| 2321 | * variables set, we do not negotiate it. see above. |
| 2322 | */ |
| 2323 | if ( may_discard |
| 2324 | && discard_variant_by_env(variant, may_discard)) { |
| 2325 | continue; |
| 2326 | } |
| 2327 | |
| 2328 | /* if a language is preferred, but the current variant |
no test coverage detected