Skip to content

Commit 99d9699

Browse files
authored
let acceptable types specify their quality (#26)
1 parent d87c40f commit 99d9699

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

mimeparse.py

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def quality_and_fitness_parsed(mime_type, parsed_ranges):
110110
])
111111
fitness += param_matches
112112

113+
# finally, add the target's "q" param (between 0 and 1)
114+
fitness += float(target_params.get('q', 1))
115+
113116
if fitness > best_fitness:
114117
best_fitness = fitness
115118
best_fit_q = params['q']

testdata.json

+16
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,22 @@
186186
"text/html",
187187
"match should use highest order of supported when there is a tie"
188188
],
189+
[
190+
[
191+
["application/json;q=1.0", "text/html;q=0.9", "text/plain;q=0.1"],
192+
"*/*"
193+
],
194+
"application/json;q=1.0",
195+
"*/* match should pick an acceptable type with the highest quality"
196+
],
197+
[
198+
[
199+
["text/html;q=0.9", "application/json", "text/plain;q=0.1"],
200+
"*/*"
201+
],
202+
"application/json",
203+
"*/* match should pick an acceptable type with the highest quality, even if it's implicit"
204+
],
189205
[
190206
[
191207
["application/json", "text/html"],

0 commit comments

Comments
 (0)