Fixed content type matching
This commit is contained in:
parent
15712773a0
commit
ec1d17dcd4
@ -6,6 +6,7 @@ module Web.Mime
|
|||||||
, contentTypeFromBS
|
, contentTypeFromBS
|
||||||
, typeByExt
|
, typeByExt
|
||||||
, ext
|
, ext
|
||||||
|
, simpleContentType
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Function (on)
|
import Data.Function (on)
|
||||||
@ -48,6 +49,9 @@ instance ConvertSuccess ContentType [Char] where
|
|||||||
convertSuccess TypeOctet = "application/octet-stream"
|
convertSuccess TypeOctet = "application/octet-stream"
|
||||||
convertSuccess (TypeOther s) = s
|
convertSuccess (TypeOther s) = s
|
||||||
|
|
||||||
|
simpleContentType :: ContentType -> String
|
||||||
|
simpleContentType = fst . span (/= ';') . cs
|
||||||
|
|
||||||
instance Eq ContentType where
|
instance Eq ContentType where
|
||||||
(==) = (==) `on` (cs :: ContentType -> String)
|
(==) = (==) `on` (cs :: ContentType -> String)
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,7 @@ parseWaiRequest env session = do
|
|||||||
$ parsePost ctype clength
|
$ parsePost ctype clength
|
||||||
inputLBS
|
inputLBS
|
||||||
rawCookie = fromMaybe B.empty $ lookup W.Cookie $ W.httpHeaders env
|
rawCookie = fromMaybe B.empty $ lookup W.Cookie $ W.httpHeaders env
|
||||||
cookies' = map (cs *** cs) $ decodeCookies rawCookie
|
cookies' = map (cs *** cs) $ parseCookies rawCookie
|
||||||
acceptLang = lookup W.AcceptLanguage $ W.httpHeaders env
|
acceptLang = lookup W.AcceptLanguage $ W.httpHeaders env
|
||||||
langs = map cs $ maybe [] parseHttpAccept acceptLang
|
langs = map cs $ maybe [] parseHttpAccept acceptLang
|
||||||
langs' = case lookup langKey cookies' of
|
langs' = case lookup langKey cookies' of
|
||||||
|
|||||||
@ -126,7 +126,8 @@ instance HasReps () where
|
|||||||
|
|
||||||
instance HasReps [(ContentType, Content)] where
|
instance HasReps [(ContentType, Content)] where
|
||||||
chooseRep a cts = return $
|
chooseRep a cts = return $
|
||||||
case filter (\(ct, _) -> ct `elem` cts) a of
|
case filter (\(ct, _) -> simpleContentType ct `elem`
|
||||||
|
map simpleContentType cts) a of
|
||||||
((ct, c):_) -> (ct, c)
|
((ct, c):_) -> (ct, c)
|
||||||
_ -> case a of
|
_ -> case a of
|
||||||
(x:_) -> x
|
(x:_) -> x
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user