MCPcopy Create free account
hub / github.com/apache/httpd / is_variant_better

Function is_variant_better

modules/mappers/mod_negotiation.c:2100–2234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2098 */
2099
2100static int is_variant_better(negotiation_state *neg, var_rec *variant,
2101 var_rec *best, float *p_bestq)
2102{
2103 float bestq = *p_bestq, q;
2104 int levcmp;
2105
2106 /* For non-transparent negotiation, server can choose how
2107 * to handle the negotiation. We'll use the following in
2108 * order: content-type, language, content-type level, charset,
2109 * content encoding, content length.
2110 *
2111 * For each check, we have three possible outcomes:
2112 * This variant is worse than current best: return 0
2113 * This variant is better than the current best:
2114 * assign this variant's q to *p_bestq, and return 1
2115 * This variant is just as desirable as the current best:
2116 * drop through to the next test.
2117 *
2118 * This code is written in this long-winded way to allow future
2119 * customisation, either by the addition of additional
2120 * checks, or to allow the order of the checks to be determined
2121 * by configuration options (e.g. we might prefer to check
2122 * language quality _before_ content type).
2123 */
2124
2125 /* First though, eliminate this variant if it is not
2126 * acceptable by type, charset, encoding or language.
2127 */
2128
2129#ifdef NEG_DEBUG
2130 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00689)
2131 "Variant: file=%s type=%s lang=%s sourceq=%1.3f "
2132 "mimeq=%1.3f langq=%1.3f langidx=%d charq=%1.3f encq=%1.3f ",
2133 (variant->file_name ? variant->file_name : ""),
2134 (variant->mime_type ? variant->mime_type : ""),
2135 (variant->content_languages
2136 ? apr_array_pstrcat(neg->pool, variant->content_languages, ',')
2137 : ""),
2138 variant->source_quality,
2139 variant->mime_type_quality,
2140 variant->lang_quality,
2141 variant->lang_index,
2142 variant->charset_quality,
2143 variant->encoding_quality);
2144#endif
2145
2146 if (variant->encoding_quality == 0.0f ||
2147 variant->lang_quality == 0.0f ||
2148 variant->source_quality == 0.0f ||
2149 variant->charset_quality == 0.0f ||
2150 variant->mime_type_quality == 0.0f) {
2151 return 0; /* don't consider unacceptables */
2152 }
2153
2154 q = variant->mime_type_quality * variant->source_quality;
2155 if (q == 0.0 || q < bestq) {
2156 return 0;
2157 }

Callers 1

best_matchFunction · 0.85

Calls 3

level_cmpFunction · 0.85
find_content_lengthFunction · 0.85
ap_log_errorFunction · 0.50

Tested by

no test coverage detected