rename util functions
This commit is contained in:
parent
cee7b1ffd1
commit
698ca2b430
2 changed files with 30 additions and 30 deletions
|
@ -7,11 +7,11 @@
|
||||||
module Servant.Server.CombinatorUtils (
|
module Servant.Server.CombinatorUtils (
|
||||||
CombinatorImplementation,
|
CombinatorImplementation,
|
||||||
runCI,
|
runCI,
|
||||||
implementCaptureCombinator,
|
makeCaptureCombinator,
|
||||||
implementRequestCheck,
|
makeRequestCheckCombinator,
|
||||||
implementAuthCombinator,
|
makeAuthCombinator,
|
||||||
argumentCombinator,
|
makeReqBodyCombinator,
|
||||||
implementRequestStreamingCombinator,
|
makeCombinator,
|
||||||
|
|
||||||
-- * re-exports
|
-- * re-exports
|
||||||
|
|
||||||
|
@ -46,57 +46,57 @@ runCI :: CombinatorImplementation combinator arg api context
|
||||||
-> Router' env RoutingApplication
|
-> Router' env RoutingApplication
|
||||||
runCI (CI i) = i
|
runCI (CI i) = i
|
||||||
|
|
||||||
implementCaptureCombinator ::
|
makeCaptureCombinator ::
|
||||||
forall api combinator arg context .
|
forall api combinator arg context .
|
||||||
(HasServer api context,
|
(HasServer api context,
|
||||||
WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler)) =>
|
WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler)) =>
|
||||||
(Text -> RouteResult arg)
|
(Text -> RouteResult arg)
|
||||||
-> CombinatorImplementation combinator arg api context
|
-> CombinatorImplementation combinator arg api context
|
||||||
implementCaptureCombinator getArg = CI $ \ Proxy context delayed ->
|
makeCaptureCombinator getArg = CI $ \ Proxy context delayed ->
|
||||||
CaptureRouter $
|
CaptureRouter $
|
||||||
route (Proxy :: Proxy api) context $ addCapture delayed $ \ captured ->
|
route (Proxy :: Proxy api) context $ addCapture delayed $ \ captured ->
|
||||||
(liftRouteResult (getArg captured))
|
(liftRouteResult (getArg captured))
|
||||||
|
|
||||||
implementRequestCheck ::
|
makeRequestCheckCombinator ::
|
||||||
forall api combinator context .
|
forall api combinator context .
|
||||||
(HasServer api context,
|
(HasServer api context,
|
||||||
WithArg () (ServerT api Handler) ~ ServerT api Handler) =>
|
WithArg () (ServerT api Handler) ~ ServerT api Handler) =>
|
||||||
(Request -> RouteResult ())
|
(Request -> RouteResult ())
|
||||||
-> CombinatorImplementation combinator () api context
|
-> CombinatorImplementation combinator () api context
|
||||||
implementRequestCheck check = CI $ \ Proxy context delayed ->
|
makeRequestCheckCombinator check = CI $ \ Proxy context delayed ->
|
||||||
route (Proxy :: Proxy api) context $ addMethodCheck delayed $
|
route (Proxy :: Proxy api) context $ addMethodCheck delayed $
|
||||||
withRequest $ \ request -> liftRouteResult $ check request
|
withRequest $ \ request -> liftRouteResult $ check request
|
||||||
|
|
||||||
implementAuthCombinator ::
|
makeAuthCombinator ::
|
||||||
forall api combinator arg context .
|
forall api combinator arg context .
|
||||||
(HasServer api context,
|
(HasServer api context,
|
||||||
WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler)) =>
|
WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler)) =>
|
||||||
(Request -> RouteResult arg)
|
(Request -> RouteResult arg)
|
||||||
-> CombinatorImplementation combinator arg api context
|
-> CombinatorImplementation combinator arg api context
|
||||||
implementAuthCombinator authCheck = CI $ \ Proxy context delayed ->
|
makeAuthCombinator authCheck = CI $ \ Proxy context delayed ->
|
||||||
route (Proxy :: Proxy api) context $ addAuthCheck delayed $
|
route (Proxy :: Proxy api) context $ addAuthCheck delayed $
|
||||||
withRequest $ \ request -> liftRouteResult $ authCheck request
|
withRequest $ \ request -> liftRouteResult $ authCheck request
|
||||||
|
|
||||||
argumentCombinator ::
|
makeReqBodyCombinator ::
|
||||||
forall api combinator arg context .
|
|
||||||
(ServerT (combinator :> api) Handler ~ (arg -> ServerT api Handler),
|
|
||||||
WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler),
|
|
||||||
HasServer api context) =>
|
|
||||||
(Request -> RouteResult arg)
|
|
||||||
-> CombinatorImplementation combinator arg api context
|
|
||||||
argumentCombinator getArg = CI $ \ Proxy context delayed ->
|
|
||||||
route (Proxy :: Proxy api) context $ addBodyCheck delayed -- fixme: shouldn't be body
|
|
||||||
(return ())
|
|
||||||
(\ () -> withRequest $ \ request -> liftRouteResult (getArg request))
|
|
||||||
|
|
||||||
implementRequestStreamingCombinator ::
|
|
||||||
forall api combinator arg context .
|
forall api combinator arg context .
|
||||||
(ServerT (combinator :> api) Handler ~ (arg -> ServerT api Handler),
|
(ServerT (combinator :> api) Handler ~ (arg -> ServerT api Handler),
|
||||||
WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler),
|
WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler),
|
||||||
HasServer api context) =>
|
HasServer api context) =>
|
||||||
(IO ByteString -> arg)
|
(IO ByteString -> arg)
|
||||||
-> CombinatorImplementation combinator arg api context
|
-> CombinatorImplementation combinator arg api context
|
||||||
implementRequestStreamingCombinator getArg = CI $ \ Proxy context delayed ->
|
makeReqBodyCombinator getArg = CI $ \ Proxy context delayed ->
|
||||||
route (Proxy :: Proxy api) context $ addBodyCheck delayed
|
route (Proxy :: Proxy api) context $ addBodyCheck delayed
|
||||||
(return ())
|
(return ())
|
||||||
(\ () -> withRequest $ \ request -> liftRouteResult $ Route $ getArg $ requestBody request)
|
(\ () -> withRequest $ \ request -> liftRouteResult $ Route $ getArg $ requestBody request)
|
||||||
|
|
||||||
|
makeCombinator ::
|
||||||
|
forall api combinator arg context .
|
||||||
|
(ServerT (combinator :> api) Handler ~ (arg -> ServerT api Handler),
|
||||||
|
WithArg arg (ServerT api Handler) ~ (arg -> ServerT api Handler),
|
||||||
|
HasServer api context) =>
|
||||||
|
(Request -> RouteResult arg)
|
||||||
|
-> CombinatorImplementation combinator arg api context
|
||||||
|
makeCombinator getArg = CI $ \ Proxy context delayed ->
|
||||||
|
route (Proxy :: Proxy api) context $ addBodyCheck delayed -- fixme: shouldn't be body
|
||||||
|
(return ())
|
||||||
|
(\ () -> withRequest $ \ request -> liftRouteResult $ getArg request)
|
||||||
|
|
|
@ -176,7 +176,7 @@ data StringCapture
|
||||||
|
|
||||||
instance HasServer api context => HasServer (StringCapture :> api) context where
|
instance HasServer api context => HasServer (StringCapture :> api) context where
|
||||||
type ServerT (StringCapture :> api) m = String -> ServerT api m
|
type ServerT (StringCapture :> api) m = String -> ServerT api m
|
||||||
route = runCI $ implementCaptureCombinator getCapture
|
route = runCI $ makeCaptureCombinator getCapture
|
||||||
|
|
||||||
getCapture :: Text -> RouteResult String
|
getCapture :: Text -> RouteResult String
|
||||||
getCapture = \case
|
getCapture = \case
|
||||||
|
@ -187,7 +187,7 @@ data CheckFooHeader
|
||||||
|
|
||||||
instance HasServer api context => HasServer (CheckFooHeader :> api) context where
|
instance HasServer api context => HasServer (CheckFooHeader :> api) context where
|
||||||
type ServerT (CheckFooHeader :> api) m = ServerT api m
|
type ServerT (CheckFooHeader :> api) m = ServerT api m
|
||||||
route = runCI $ implementRequestCheck checkFooHeader
|
route = runCI $ makeRequestCheckCombinator checkFooHeader
|
||||||
|
|
||||||
checkFooHeader :: Request -> RouteResult ()
|
checkFooHeader :: Request -> RouteResult ()
|
||||||
checkFooHeader request = case lookup "Foo" (requestHeaders request) of
|
checkFooHeader request = case lookup "Foo" (requestHeaders request) of
|
||||||
|
@ -201,7 +201,7 @@ data User = User String
|
||||||
|
|
||||||
instance HasServer api context => HasServer (AuthCombinator :> api) context where
|
instance HasServer api context => HasServer (AuthCombinator :> api) context where
|
||||||
type ServerT (AuthCombinator :> api) m = User -> ServerT api m
|
type ServerT (AuthCombinator :> api) m = User -> ServerT api m
|
||||||
route = runCI $ implementAuthCombinator checkAuth
|
route = runCI $ makeAuthCombinator checkAuth
|
||||||
|
|
||||||
checkAuth :: Request -> RouteResult User
|
checkAuth :: Request -> RouteResult User
|
||||||
checkAuth request = case lookup "Auth" (requestHeaders request) of
|
checkAuth request = case lookup "Auth" (requestHeaders request) of
|
||||||
|
@ -213,7 +213,7 @@ data FooHeader
|
||||||
|
|
||||||
instance HasServer api context => HasServer (FooHeader :> api) context where
|
instance HasServer api context => HasServer (FooHeader :> api) context where
|
||||||
type ServerT (FooHeader :> api) m = String -> ServerT api m
|
type ServerT (FooHeader :> api) m = String -> ServerT api m
|
||||||
route = runCI $ argumentCombinator getCustom
|
route = runCI $ makeCombinator getCustom
|
||||||
|
|
||||||
getCustom :: Request -> RouteResult String
|
getCustom :: Request -> RouteResult String
|
||||||
getCustom request = case lookup "Foo" (requestHeaders request) of
|
getCustom request = case lookup "Foo" (requestHeaders request) of
|
||||||
|
@ -226,7 +226,7 @@ data Source = Source (IO SBS.ByteString)
|
||||||
|
|
||||||
instance HasServer api context => HasServer (StreamRequest :> api) context where
|
instance HasServer api context => HasServer (StreamRequest :> api) context where
|
||||||
type ServerT (StreamRequest :> api) m = Source -> ServerT api m
|
type ServerT (StreamRequest :> api) m = Source -> ServerT api m
|
||||||
route = runCI $ implementRequestStreamingCombinator getSource
|
route = runCI $ makeReqBodyCombinator getSource
|
||||||
|
|
||||||
getSource :: IO SBS.ByteString -> Source
|
getSource :: IO SBS.ByteString -> Source
|
||||||
getSource = Source
|
getSource = Source
|
||||||
|
|
Loading…
Reference in a new issue