From 3d9a151412db831d93511d201c741d43153de668 Mon Sep 17 00:00:00 2001 From: Sasa Bogicevic Date: Fri, 27 Apr 2018 11:34:03 +0200 Subject: [PATCH] Add helper functions --- servant-server/src/Servant/Server.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/servant-server/src/Servant/Server.hs b/servant-server/src/Servant/Server.hs index c5c4e1fe..732038f4 100644 --- a/servant-server/src/Servant/Server.hs +++ b/servant-server/src/Servant/Server.hs @@ -10,6 +10,8 @@ module Servant.Server ( -- * Run a wai application from an API serve , serveWithContext + , fullyEvalResponse + , noEvalResponse , -- * Construct a wai Application from an API toApplication @@ -124,16 +126,23 @@ import Servant.Server.Internal -- serve :: (HasServer api '[Bool]) => Proxy api -> Server api -> Application -serve p = serveWithContext p (False :. EmptyContext) +serve p = serveWithContext p noEvalResponse serveWithContext :: (HasServer api context, HasContextEntry context Bool) => Proxy api -> Context context -> Server api -> Application serveWithContext p context server = toApplication - (getContextEntry context :: Bool) + ((getContextEntry context :: Bool) || False) -- ^ determins if we should fully evaluate response + -- defaults to False (runRouter (route p context (emptyDelayed (Route server)))) +fullyEvalResponse :: Context '[Bool] +fullyEvalResponse = True :. EmptyContext + +noEvalResponse :: Context '[Bool] +noEvalResponse = False :. EmptyContext + -- | Hoist server implementation. -- -- Sometimes our cherished `Handler` monad isn't quite the type you'd like for