module Network.GRPC.Server.Session (
ServerSession(..)
, ServerInbound
, ServerOutbound
, Headers(..)
, CallSetupFailure(..)
) where
import Control.Exception
import Data.Proxy
import Data.Void
import Network.GRPC.Server.Context
import Network.GRPC.Spec
import Network.GRPC.Spec.Serialization
import Network.GRPC.Util.Session
data ServerSession rpc = ServerSession {
forall {k} (rpc :: k). ServerSession rpc -> ServerContext
serverSessionContext :: ServerContext
}
data ServerInbound rpc
data ServerOutbound rpc
instance IsRPC rpc => DataFlow (ServerInbound rpc) where
data (ServerInbound rpc) = {
:: RequestHeaders' HandledSynthesized
, forall k (rpc :: k). Headers (ServerInbound rpc) -> Compression
inbCompression :: Compression
}
deriving (Int -> Headers (ServerInbound rpc) -> ShowS
[Headers (ServerInbound rpc)] -> ShowS
Headers (ServerInbound rpc) -> String
(Int -> Headers (ServerInbound rpc) -> ShowS)
-> (Headers (ServerInbound rpc) -> String)
-> ([Headers (ServerInbound rpc)] -> ShowS)
-> Show (Headers (ServerInbound rpc))
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (rpc :: k). Int -> Headers (ServerInbound rpc) -> ShowS
forall k (rpc :: k). [Headers (ServerInbound rpc)] -> ShowS
forall k (rpc :: k). Headers (ServerInbound rpc) -> String
$cshowsPrec :: forall k (rpc :: k). Int -> Headers (ServerInbound rpc) -> ShowS
showsPrec :: Int -> Headers (ServerInbound rpc) -> ShowS
$cshow :: forall k (rpc :: k). Headers (ServerInbound rpc) -> String
show :: Headers (ServerInbound rpc) -> String
$cshowList :: forall k (rpc :: k). [Headers (ServerInbound rpc)] -> ShowS
showList :: [Headers (ServerInbound rpc)] -> ShowS
Show)
type Message (ServerInbound rpc) = (InboundMeta, Input rpc)
type Trailers (ServerInbound rpc) = NoMetadata
type NoMessages (ServerInbound rpc) = Void
instance IsRPC rpc => DataFlow (ServerOutbound rpc) where
data (ServerOutbound rpc) = {
:: ResponseHeaders
, forall k (rpc :: k). Headers (ServerOutbound rpc) -> Compression
outCompression :: Compression
}
deriving (Int -> Headers (ServerOutbound rpc) -> ShowS
[Headers (ServerOutbound rpc)] -> ShowS
Headers (ServerOutbound rpc) -> String
(Int -> Headers (ServerOutbound rpc) -> ShowS)
-> (Headers (ServerOutbound rpc) -> String)
-> ([Headers (ServerOutbound rpc)] -> ShowS)
-> Show (Headers (ServerOutbound rpc))
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (rpc :: k). Int -> Headers (ServerOutbound rpc) -> ShowS
forall k (rpc :: k). [Headers (ServerOutbound rpc)] -> ShowS
forall k (rpc :: k). Headers (ServerOutbound rpc) -> String
$cshowsPrec :: forall k (rpc :: k). Int -> Headers (ServerOutbound rpc) -> ShowS
showsPrec :: Int -> Headers (ServerOutbound rpc) -> ShowS
$cshow :: forall k (rpc :: k). Headers (ServerOutbound rpc) -> String
show :: Headers (ServerOutbound rpc) -> String
$cshowList :: forall k (rpc :: k). [Headers (ServerOutbound rpc)] -> ShowS
showList :: [Headers (ServerOutbound rpc)] -> ShowS
Show)
type Message (ServerOutbound rpc) = (OutboundMeta, Output rpc)
type Trailers (ServerOutbound rpc) = ProperTrailers
type NoMessages (ServerOutbound rpc) = TrailersOnly
instance SupportsServerRpc rpc => IsSession (ServerSession rpc) where
type Inbound (ServerSession rpc) = ServerInbound rpc
type Outbound (ServerSession rpc) = ServerOutbound rpc
parseInboundTrailers :: ServerSession rpc
-> [Header] -> IO (Trailers (Inbound (ServerSession rpc)))
parseInboundTrailers ServerSession rpc
_ = \[Header]
_ -> NoMetadata -> IO NoMetadata
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return NoMetadata
NoMetadata
buildOutboundTrailers :: ServerSession rpc
-> Trailers (Outbound (ServerSession rpc)) -> [Header]
buildOutboundTrailers ServerSession rpc
_ = ProperTrailers -> [Header]
Trailers (Outbound (ServerSession rpc)) -> [Header]
buildProperTrailers
parseMsg :: ServerSession rpc
-> Headers (Inbound (ServerSession rpc))
-> Parser String (Message (Inbound (ServerSession rpc)))
parseMsg ServerSession rpc
_ = Proxy rpc -> Compression -> Parser String (InboundMeta, Input rpc)
forall {k} (rpc :: k).
SupportsServerRpc rpc =>
Proxy rpc -> Compression -> Parser String (InboundMeta, Input rpc)
parseInput (forall (t :: k). Proxy t
forall {k} (t :: k). Proxy t
Proxy @rpc) (Compression -> Parser String (InboundMeta, Input rpc))
-> (Headers (ServerInbound rpc) -> Compression)
-> Headers (ServerInbound rpc)
-> Parser String (InboundMeta, Input rpc)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Headers (ServerInbound rpc) -> Compression
forall k (rpc :: k). Headers (ServerInbound rpc) -> Compression
inbCompression
buildMsg :: ServerSession rpc
-> Headers (Outbound (ServerSession rpc))
-> Message (Outbound (ServerSession rpc))
-> Builder
buildMsg ServerSession rpc
_ = Proxy rpc -> Compression -> (OutboundMeta, Output rpc) -> Builder
forall {k} (rpc :: k).
SupportsServerRpc rpc =>
Proxy rpc -> Compression -> (OutboundMeta, Output rpc) -> Builder
buildOutput (forall (t :: k). Proxy t
forall {k} (t :: k). Proxy t
Proxy @rpc) (Compression -> (OutboundMeta, Output rpc) -> Builder)
-> (Headers (ServerOutbound rpc) -> Compression)
-> Headers (ServerOutbound rpc)
-> (OutboundMeta, Output rpc)
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Headers (ServerOutbound rpc) -> Compression
forall k (rpc :: k). Headers (ServerOutbound rpc) -> Compression
outCompression
data CallSetupFailure =
InvalidResourceHeaders
| (InvalidHeaders HandledSynthesized)
| CallSetupUnsupportedCompression CompressionId
| CallSetupUnimplementedMethod Path
| CallSetupHandlerLookupException SomeException
deriving stock instance Show CallSetupFailure
deriving anyclass instance Exception CallSetupFailure