module Network.GRPC.Spec.Headers.PseudoHeaders (
ServerHeaders(..)
, ResourceHeaders(..)
, PseudoHeaders(..)
, Method(..)
, Scheme(..)
, Address(..)
, Path(..)
, rpcPath
) where
import Data.ByteString qualified as Strict (ByteString)
import Data.Hashable
import Data.Proxy
import Network.Socket (HostName, PortNumber)
import Network.GRPC.Spec.RPC
data = {
ServerHeaders -> Scheme
serverScheme :: Scheme
, ServerHeaders -> Address
serverAddress :: Address
}
deriving stock (Int -> ServerHeaders -> ShowS
[ServerHeaders] -> ShowS
ServerHeaders -> String
(Int -> ServerHeaders -> ShowS)
-> (ServerHeaders -> String)
-> ([ServerHeaders] -> ShowS)
-> Show ServerHeaders
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ServerHeaders -> ShowS
showsPrec :: Int -> ServerHeaders -> ShowS
$cshow :: ServerHeaders -> String
show :: ServerHeaders -> String
$cshowList :: [ServerHeaders] -> ShowS
showList :: [ServerHeaders] -> ShowS
Show)
data = {
ResourceHeaders -> Method
resourceMethod :: Method
, ResourceHeaders -> Path
resourcePath :: Path
}
deriving stock (Int -> ResourceHeaders -> ShowS
[ResourceHeaders] -> ShowS
ResourceHeaders -> String
(Int -> ResourceHeaders -> ShowS)
-> (ResourceHeaders -> String)
-> ([ResourceHeaders] -> ShowS)
-> Show ResourceHeaders
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ResourceHeaders -> ShowS
showsPrec :: Int -> ResourceHeaders -> ShowS
$cshow :: ResourceHeaders -> String
show :: ResourceHeaders -> String
$cshowList :: [ResourceHeaders] -> ShowS
showList :: [ResourceHeaders] -> ShowS
Show)
data = {
:: ServerHeaders
, :: ResourceHeaders
}
deriving stock (Int -> PseudoHeaders -> ShowS
[PseudoHeaders] -> ShowS
PseudoHeaders -> String
(Int -> PseudoHeaders -> ShowS)
-> (PseudoHeaders -> String)
-> ([PseudoHeaders] -> ShowS)
-> Show PseudoHeaders
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PseudoHeaders -> ShowS
showsPrec :: Int -> PseudoHeaders -> ShowS
$cshow :: PseudoHeaders -> String
show :: PseudoHeaders -> String
$cshowList :: [PseudoHeaders] -> ShowS
showList :: [PseudoHeaders] -> ShowS
Show)
data Method = Post
deriving stock (Int -> Method -> ShowS
[Method] -> ShowS
Method -> String
(Int -> Method -> ShowS)
-> (Method -> String) -> ([Method] -> ShowS) -> Show Method
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Method -> ShowS
showsPrec :: Int -> Method -> ShowS
$cshow :: Method -> String
show :: Method -> String
$cshowList :: [Method] -> ShowS
showList :: [Method] -> ShowS
Show)
data Scheme = Http | Https
deriving stock (Int -> Scheme -> ShowS
[Scheme] -> ShowS
Scheme -> String
(Int -> Scheme -> ShowS)
-> (Scheme -> String) -> ([Scheme] -> ShowS) -> Show Scheme
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Scheme -> ShowS
showsPrec :: Int -> Scheme -> ShowS
$cshow :: Scheme -> String
show :: Scheme -> String
$cshowList :: [Scheme] -> ShowS
showList :: [Scheme] -> ShowS
Show)
data Address = Address {
Address -> String
addressHost :: HostName
, Address -> PortNumber
addressPort :: PortNumber
, Address -> Maybe String
addressAuthority :: Maybe String
}
deriving stock (Int -> Address -> ShowS
[Address] -> ShowS
Address -> String
(Int -> Address -> ShowS)
-> (Address -> String) -> ([Address] -> ShowS) -> Show Address
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Address -> ShowS
showsPrec :: Int -> Address -> ShowS
$cshow :: Address -> String
show :: Address -> String
$cshowList :: [Address] -> ShowS
showList :: [Address] -> ShowS
Show)
data Path = Path {
Path -> ByteString
pathService :: Strict.ByteString
, Path -> ByteString
pathMethod :: Strict.ByteString
}
deriving stock (Int -> Path -> ShowS
[Path] -> ShowS
Path -> String
(Int -> Path -> ShowS)
-> (Path -> String) -> ([Path] -> ShowS) -> Show Path
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Path -> ShowS
showsPrec :: Int -> Path -> ShowS
$cshow :: Path -> String
show :: Path -> String
$cshowList :: [Path] -> ShowS
showList :: [Path] -> ShowS
Show, Path -> Path -> Bool
(Path -> Path -> Bool) -> (Path -> Path -> Bool) -> Eq Path
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Path -> Path -> Bool
== :: Path -> Path -> Bool
$c/= :: Path -> Path -> Bool
/= :: Path -> Path -> Bool
Eq)
instance Hashable Path where
hashWithSalt :: Int -> Path -> Int
hashWithSalt Int
salt Path{ByteString
pathService :: Path -> ByteString
pathService :: ByteString
pathService, ByteString
pathMethod :: Path -> ByteString
pathMethod :: ByteString
pathMethod} =
Int -> (ByteString, ByteString) -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (ByteString
pathService, ByteString
pathMethod)
rpcPath :: IsRPC rpc => Proxy rpc -> Path
rpcPath :: forall {k} (rpc :: k). IsRPC rpc => Proxy rpc -> Path
rpcPath Proxy rpc
proxy = ByteString -> ByteString -> Path
Path (Proxy rpc -> ByteString
forall k (rpc :: k).
(IsRPC rpc, HasCallStack) =>
Proxy rpc -> ByteString
rpcServiceName Proxy rpc
proxy) (Proxy rpc -> ByteString
forall k (rpc :: k).
(IsRPC rpc, HasCallStack) =>
Proxy rpc -> ByteString
rpcMethodName Proxy rpc
proxy)