* set_encoding_quality determines whether the encoding for a particular * variant is acceptable for the user-agent. * * The rules for encoding are that if the user-agent does not supply * any Accept-Encoding header, then all encodings are allowed but a * variant with no encoding should be preferred. * If there is an empty Accept-Encoding header, then no encodings are * acceptable. If there
| 1936 | * unless the "identity" encoding is specifically excluded. |
| 1937 | */ |
| 1938 | static void set_encoding_quality(negotiation_state *neg, var_rec *variant) |
| 1939 | { |
| 1940 | accept_rec *accept_recs; |
| 1941 | const char *enc = variant->content_encoding; |
| 1942 | accept_rec *star = NULL; |
| 1943 | float value_if_not_found = 0.0f; |
| 1944 | int i; |
| 1945 | |
| 1946 | if (!neg->accept_encodings) { |
| 1947 | /* We had no Accept-Encoding header, assume that all |
| 1948 | * encodings are acceptable with a low quality, |
| 1949 | * but we prefer no encoding if available. |
| 1950 | */ |
| 1951 | if (!enc || is_identity_encoding(enc)) |
| 1952 | variant->encoding_quality = 1.0f; |
| 1953 | else |
| 1954 | variant->encoding_quality = 0.5f; |
| 1955 | |
| 1956 | return; |
| 1957 | } |
| 1958 | |
| 1959 | if (!enc || is_identity_encoding(enc)) { |
| 1960 | enc = "identity"; |
| 1961 | value_if_not_found = 0.0001f; |
| 1962 | } |
| 1963 | |
| 1964 | accept_recs = (accept_rec *) neg->accept_encodings->elts; |
| 1965 | |
| 1966 | /* Go through each of the encodings on the Accept-Encoding: header, |
| 1967 | * looking for a match with our encoding. x- prefixes are ignored. |
| 1968 | */ |
| 1969 | if (enc[0] == 'x' && enc[1] == '-') { |
| 1970 | enc += 2; |
| 1971 | } |
| 1972 | for (i = 0; i < neg->accept_encodings->nelts; ++i) { |
| 1973 | |
| 1974 | char *name = accept_recs[i].name; |
| 1975 | |
| 1976 | if (name[0] == 'x' && name[1] == '-') { |
| 1977 | name += 2; |
| 1978 | } |
| 1979 | |
| 1980 | if (!strcmp(name, enc)) { |
| 1981 | variant->encoding_quality = accept_recs[i].quality; |
| 1982 | return; |
| 1983 | } |
| 1984 | |
| 1985 | if (strcmp(name, "*") == 0) { |
| 1986 | star = &accept_recs[i]; |
| 1987 | } |
| 1988 | |
| 1989 | } |
| 1990 | /* No explicit match */ |
| 1991 | if (star) { |
| 1992 | variant->encoding_quality = star->quality; |
| 1993 | return; |
| 1994 | } |
| 1995 |
no test coverage detected