| 1763 | */ |
| 1764 | |
| 1765 | static void set_accept_quality(negotiation_state *neg, var_rec *variant) |
| 1766 | { |
| 1767 | int i; |
| 1768 | accept_rec *accept_recs; |
| 1769 | float q = 0.0f; |
| 1770 | int q_definite = 1; |
| 1771 | |
| 1772 | /* if no Accept: header, leave quality alone (will |
| 1773 | * remain at the default value of 1) |
| 1774 | * |
| 1775 | * XXX: This if is currently never true because of the effect of |
| 1776 | * maybe_add_default_accepts(). |
| 1777 | */ |
| 1778 | if (!neg->accepts) { |
| 1779 | if (variant->mime_type && *variant->mime_type) |
| 1780 | variant->definite = 0; |
| 1781 | return; |
| 1782 | } |
| 1783 | |
| 1784 | accept_recs = (accept_rec *) neg->accepts->elts; |
| 1785 | |
| 1786 | /* |
| 1787 | * Go through each of the ranges on the Accept: header, |
| 1788 | * looking for the 'best' match with this variant's |
| 1789 | * content-type. We use the best match's quality |
| 1790 | * value (from the Accept: header) for this variant's |
| 1791 | * mime_type_quality field. |
| 1792 | * |
| 1793 | * The best match is determined like this: |
| 1794 | * type/type is better than type/ * is better than * / * |
| 1795 | * if match is type/type, use the level mime param if available |
| 1796 | */ |
| 1797 | for (i = 0; i < neg->accepts->nelts; ++i) { |
| 1798 | |
| 1799 | accept_rec *type = &accept_recs[i]; |
| 1800 | int prev_mime_stars; |
| 1801 | |
| 1802 | prev_mime_stars = variant->mime_stars; |
| 1803 | |
| 1804 | if (!mime_match(type, variant)) { |
| 1805 | continue; /* didn't match the content type at all */ |
| 1806 | } |
| 1807 | else { |
| 1808 | /* did match - see if there were less or more stars than |
| 1809 | * in previous match |
| 1810 | */ |
| 1811 | if (prev_mime_stars == variant->mime_stars) { |
| 1812 | continue; /* more stars => not as good a match */ |
| 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | /* If we are allowed to mess with the q-values |
| 1817 | * and have no explicit q= parameters in the accept header, |
| 1818 | * make wildcards very low, so we have a low chance |
| 1819 | * of ending up with them if there's something better. |
| 1820 | */ |
| 1821 | |
| 1822 | if (!neg->dont_fiddle_headers && !neg->accept_q && |
no test coverage detected