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

Function is_variant_better_rvsa

modules/mappers/mod_negotiation.c:2033–2094  ·  view source on GitHub ↗

Firstly, the RVSA/1.0 (HTTP Remote Variant Selection Algorithm * v1.0) from rfc2296. This is the algorithm that goes together with * transparent content negotiation (TCN). */

Source from the content-addressed store, hash-verified

2031 * transparent content negotiation (TCN).
2032 */
2033static int is_variant_better_rvsa(negotiation_state *neg, var_rec *variant,
2034 var_rec *best, float *p_bestq)
2035{
2036 float bestq = *p_bestq, q;
2037
2038 /* TCN does not cover negotiation on content-encoding. For now,
2039 * we ignore the encoding unless it was explicitly excluded.
2040 */
2041 if (variant->encoding_quality == 0.0f)
2042 return 0;
2043
2044 q = variant->mime_type_quality *
2045 variant->source_quality *
2046 variant->charset_quality *
2047 variant->lang_quality;
2048
2049 /* RFC 2296 calls for the result to be rounded to 5 decimal places,
2050 * but we don't do that because it serves no useful purpose other
2051 * than to ensure that a remote algorithm operates on the same
2052 * precision as ours. That is silly, since what we obviously want
2053 * is for the algorithm to operate on the best available precision
2054 * regardless of who runs it. Since the above calculation may
2055 * result in significant variance at 1e-12, rounding would be bogus.
2056 */
2057
2058#ifdef NEG_DEBUG
2059 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00688)
2060 "Variant: file=%s type=%s lang=%s sourceq=%1.3f "
2061 "mimeq=%1.3f langq=%1.3f charq=%1.3f encq=%1.3f "
2062 "q=%1.5f definite=%d",
2063 (variant->file_name ? variant->file_name : ""),
2064 (variant->mime_type ? variant->mime_type : ""),
2065 (variant->content_languages
2066 ? apr_array_pstrcat(neg->pool, variant->content_languages, ',')
2067 : ""),
2068 variant->source_quality,
2069 variant->mime_type_quality,
2070 variant->lang_quality,
2071 variant->charset_quality,
2072 variant->encoding_quality,
2073 q,
2074 variant->definite);
2075#endif
2076
2077 if (q <= 0.0f) {
2078 return 0;
2079 }
2080 if (q > bestq) {
2081 *p_bestq = q;
2082 return 1;
2083 }
2084 if (q == bestq) {
2085 /* If the best variant's encoding is of lesser quality than
2086 * this variant, then we prefer this variant
2087 */
2088 if (variant->encoding_quality > best->encoding_quality) {
2089 *p_bestq = q;
2090 return 1;

Callers 1

best_matchFunction · 0.85

Calls 1

ap_log_errorFunction · 0.50

Tested by

no test coverage detected