make QueryFlag more permissive

This commit is contained in:
Alp Mestanogullari 2014-10-31 13:01:12 +01:00
parent a9eeff14bd
commit 0802221789
2 changed files with 16 additions and 2 deletions

View file

@ -133,11 +133,14 @@ instance (KnownSymbol sym, HasServer sublayout)
let querytext = parseQueryText $ rawQueryString request
param = case lookup paramname querytext of
Just Nothing -> True -- param is there, with no value
_ -> False -- param not in the query string or with a value
Just (Just v) -> examine v -- param with a value
Nothing -> False -- param not in the query string
route (Proxy :: Proxy sublayout) (subserver param) request respond
where paramname = cs $ symbolVal (Proxy :: Proxy sym)
examine v | v == "true" || v == "1" || v == "" = True
| otherwise = False
instance (KnownSymbol sym, HasClient sublayout)
=> HasClient (QueryFlag sym :> sublayout) where

View file

@ -178,6 +178,17 @@ queryParamSpec = do
name = "ALICE"
}
let params3' = "?capitalize="
response3' <- Network.Wai.Test.request defaultRequest{
rawQueryString = params3',
queryString = parseQuery params3',
pathInfo = ["b"]
}
liftIO $
decode' (simpleBody response3') `shouldBe` Just alice{
name = "ALICE"
}
type PostApi = ReqBody Person :> Post Integer
postApi :: Proxy PostApi
postApi = Proxy