@@ -1,6 +1,7 @@
11{-# LANGUAGE DataKinds #-}
2−{-# LANGUAGE TypeOperators #-}
32{-# LANGUAGE GADTs #-}
3+{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE TypeOperators #-}
45{-# LANGUAGE ViewPatterns #-}
56
67module Servant.ClientSpec where
@@ -8,10 +9,12 @@ module Servant.ClientSpec where
89import Control.Concurrent
910import Control.Exception
1011import Control.Monad.Trans.Either
12+import Data.ByteString.Lazy (ByteString)
1113import Data.Char
1214import Data.Foldable (forM_)
1315import Data.Proxy
1416import Data.Typeable
17+import Network.HTTP.Types
1518import Network.Socket
1619import Network.Wai
1720import Network.Wai.Handler.Warp
@@ -33,6 +36,8 @@ type Api =
3336 :<|> "param" :> QueryParam "name" String :> Get Person
3437 :<|> "params" :> QueryParams "names" String :> Get [Person]
3538 :<|> "flag" :> QueryFlag "flag" :> Get Bool
39+ :<|> "rawSuccess" :> Raw
40+ :<|> "rawFailure" :> Raw
3641 :<|> "multiple" :>
3742 Capture "first" String :>
3843 QueryParam "second" Int :>
@@ -53,6 +58,8 @@ server = serve api (
5358 Nothing -> left (400, "missing parameter"))
5459 :<|> (\ names -> return (zipWith Person names [0..]))
5560 :<|> return
61+ :<|> (\ _request respond -> respond $ responseLBS ok200 [] "rawSuccess")
62+ :<|> (\ _request respond -> respond $ responseLBS badRequest400 [] "rawFailure")
5663 :<|> \ a b c d -> return (a, b, c, d)
5764 )
5865
@@ -65,6 +72,8 @@ getBody :: Person -> BaseUrl -> EitherT String IO Person
6572getQueryParam :: Maybe String -> BaseUrl -> EitherT String IO Person
6673getQueryParams :: [String] -> BaseUrl -> EitherT String IO [Person]
6774getQueryFlag :: Bool -> BaseUrl -> EitherT String IO Bool
75+getRawSuccess :: Method -> BaseUrl -> EitherT String IO ByteString
76+getRawFailure :: Method -> BaseUrl -> EitherT String IO ByteString
6877getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])]
6978 -> BaseUrl
7079 -> EitherT String IO (String, Maybe Int, Bool, [(String, [Rational])])
@@ -74,6 +83,8 @@ getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])]
7483 :<|> getQueryParam
7584 :<|> getQueryParams
7685 :<|> getQueryFlag
86+ :<|> getRawSuccess
87+ :<|> getRawFailure
7788 :<|> getMultiple)
7889 = client api
7990