Skip to content

Commit

Permalink
let acceptable types specify their quality (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojcikstefan authored Oct 16, 2016
1 parent d87c40f commit 99d9699
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mimeparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def quality_and_fitness_parsed(mime_type, parsed_ranges):
])
fitness += param_matches

# finally, add the target's "q" param (between 0 and 1)
fitness += float(target_params.get('q', 1))

if fitness > best_fitness:
best_fitness = fitness
best_fit_q = params['q']
Expand Down
16 changes: 16 additions & 0 deletions testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@
"text/html",
"match should use highest order of supported when there is a tie"
],
[
[
["application/json;q=1.0", "text/html;q=0.9", "text/plain;q=0.1"],
"*/*"
],
"application/json;q=1.0",
"*/* match should pick an acceptable type with the highest quality"
],
[
[
["text/html;q=0.9", "application/json", "text/plain;q=0.1"],
"*/*"
],
"application/json",
"*/* match should pick an acceptable type with the highest quality, even if it's implicit"
],
[
[
["application/json", "text/html"],
Expand Down

0 comments on commit 99d9699

Please sign in to comment.