Use Evaluate instead of Bool
This commit is contained in:
parent
465e0b8f10
commit
a786dc421f
4 changed files with 13 additions and 6 deletions
|
@ -132,7 +132,7 @@ serve p = serveWithContext p EmptyContext
|
|||
serveWithContext :: (HasServer api context)
|
||||
=> Proxy api -> Context context -> Server api -> Application
|
||||
serveWithContext p context server =
|
||||
toApplication True (runRouter (route p context (emptyDelayed (Route server))))
|
||||
toApplication Force (runRouter (route p context (emptyDelayed (Route server))))
|
||||
|
||||
-- | Hoist server implementation.
|
||||
--
|
||||
|
|
|
@ -46,3 +46,10 @@ instance MonadBaseControl IO Handler where
|
|||
|
||||
runHandler :: Handler a -> IO (Either ServantErr a)
|
||||
runHandler = runExceptT . runHandler'
|
||||
|
||||
-- determins if response should be reduced to NF
|
||||
data Evaluate =
|
||||
Force
|
||||
| Lazy
|
||||
deriving (Show)
|
||||
|
||||
|
|
|
@ -95,16 +95,16 @@ instance MonadTransControl RouteResultT where
|
|||
instance MonadThrow m => MonadThrow (RouteResultT m) where
|
||||
throwM = lift . throwM
|
||||
|
||||
toApplication :: Bool -> RoutingApplication -> Application
|
||||
toApplication :: Evaluate -> RoutingApplication -> Application
|
||||
toApplication fullyEvaluate ra request respond =
|
||||
ra request (maybeEval routingRespond)
|
||||
where
|
||||
maybeEval :: (RouteResult Response -> IO ResponseReceived)
|
||||
-> RouteResult Response -> IO ResponseReceived
|
||||
maybeEval resp =
|
||||
if fullyEvaluate
|
||||
then force resp
|
||||
else resp
|
||||
case fullyEvaluate of
|
||||
Force -> force resp
|
||||
Lazy -> resp
|
||||
routingRespond :: RouteResult Response -> IO ResponseReceived
|
||||
routingRespond (Fail err) = respond $ responseServantErr err
|
||||
routingRespond (FailFatal err) = respond $ responseServantErr err
|
||||
|
|
|
@ -31,7 +31,7 @@ spec = describe "Servant.Server.Internal.Router" $ do
|
|||
routerSpec :: Spec
|
||||
routerSpec = do
|
||||
let app' :: Application
|
||||
app' = toApplication $ runRouter router'
|
||||
app' = toApplication Force $ runRouter router'
|
||||
|
||||
router', router :: Router ()
|
||||
router' = tweakResponse (fmap twk) router
|
||||
|
|
Loading…
Reference in a new issue