Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: singpolyma/wai
...
head fork: singpolyma/wai
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 12 additions and 6 deletions.
  1. +12 −6 wai-extra/Network/Wai/Parse.hs
View
18 wai-extra/Network/Wai/Parse.hs
@@ -58,19 +58,25 @@ 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 =
- let (s', q) = breakDiscard 59 s -- semicolon
- (_, q') = breakDiscard 61 q -- equals sign
- in (trimWhite s', readQ $ trimWhite q')
+ -- Stripping all spaces may be too harsh.
+ -- Maybe just strip either side of semicolon?
+ let (s', q) = S.breakSubstring ";q=" (S.filter (/=0x20) s) -- 0x20 is space
+ q' = S.takeWhile (/=0x3B) (S.drop 3 q) -- 0x3B is semicolon
+ in (s', readQ q')
readQ s = case reads $ S8.unpack s of
(x, _):_ -> x
_ -> 1.0
- trimWhite = S.dropWhile (== 32) -- space
-- | Store uploaded files in memory
lbsBackEnd :: Monad m => ignored1 -> ignored2 -> Sink S.ByteString m L.ByteString

No commit comments for this range

Something went wrong with that request. Please try again.