Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Order by specificity for items with the same q

Closes #118
  • Loading branch information...
commit ecd53e3febedb5c6d911a56886e80d111aafceef 1 parent 51b81d3
@singpolyma authored
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?
Please sign in to comment.
Something went wrong with that request. Please try again.