Skip to content
Browse files

Order by specificity for items with the same q

Closes #118
  • Loading branch information...
1 parent 51b81d3 commit ecd53e3febedb5c6d911a56886e80d111aafceef @singpolyma committed Oct 9, 2012
Showing with 7 additions and 2 deletions.
  1. +7 −2 wai-extra/Network/Wai/Parse.hs
View
9 wai-extra/Network/Wai/Parse.hs
@@ -58,11 +58,16 @@ breakDiscard w s =
parseHttpAccept :: S.ByteString -> [S.ByteString]
parseHttpAccept = map fst
. sortBy (rcompare `on` snd)
- . map grabQ
+ . map (addSpecificity . grabQ)
. S.split 44 -- comma
where
- rcompare :: Double -> Double -> Ordering
+ rcompare :: (Double,Int) -> (Double,Int) -> Ordering
rcompare = flip compare
+ addSpecificity (s, q) =
+ -- Prefer higher-specificity types
+ let semicolons = S.count 0x3B s
+ stars = S.count 0x2A s
+ in (s, (q, semicolons - stars))
grabQ s =
-- Stripping all spaces may be too harsh.
-- Maybe just strip either side of semicolon?

0 comments on commit ecd53e3

Please sign in to comment.
Something went wrong with that request. Please try again.