Expose max receive message length channel arg in ServiceOptions

This commit is contained in:
Joel Stanley 2020-11-02 11:44:49 -06:00
parent d8f6e0b476
commit e9538d7db8
No known key found for this signature in database
GPG key ID: 38D3B3C63EFFAB64
4 changed files with 11 additions and 1 deletions

View file

@ -1,5 +1,5 @@
name: grpc-haskell name: grpc-haskell
version: 0.0.1.0 version: 0.0.1.1
synopsis: Haskell implementation of gRPC layered on shared C library. synopsis: Haskell implementation of gRPC layered on shared C library.
homepage: https://github.com/awakenetworks/gRPC-haskell homepage: https://github.com/awakenetworks/gRPC-haskell
license: Apache-2.0 license: Apache-2.0

View file

@ -42,6 +42,8 @@ import Network.GRPC.HighLevel.Server
import Network.GRPC.HighLevel.Client import Network.GRPC.HighLevel.Client
import Network.GRPC.LowLevel import Network.GRPC.LowLevel
import Network.GRPC.LowLevel.Call import Network.GRPC.LowLevel.Call
import qualified Network.GRPC.Unsafe.ChannelArgs as C
import Numeric.Natural
import System.IO (hPutStrLn, stderr) import System.IO (hPutStrLn, stderr)
-- | Used at the kind level as a parameter to service definitions -- | Used at the kind level as a parameter to service definitions
@ -78,6 +80,8 @@ data ServiceOptions = ServiceOptions
-- ^ Security configuration. -- ^ Security configuration.
, logger :: String -> IO () , logger :: String -> IO ()
-- ^ Logging function to use to log errors in handling calls. -- ^ Logging function to use to log errors in handling calls.
, serverMaxReceiveMessageLength :: Maybe Natural
-- ^ Maximum length (in bytes) that the service may receive in a single message
} }
defaultServiceOptions :: ServiceOptions defaultServiceOptions :: ServiceOptions
@ -91,6 +95,7 @@ defaultServiceOptions = ServiceOptions
, Network.GRPC.HighLevel.Generated.initialMetadata = mempty , Network.GRPC.HighLevel.Generated.initialMetadata = mempty
, Network.GRPC.HighLevel.Generated.sslConfig = Nothing , Network.GRPC.HighLevel.Generated.sslConfig = Nothing
, Network.GRPC.HighLevel.Generated.logger = hPutStrLn stderr , Network.GRPC.HighLevel.Generated.logger = hPutStrLn stderr
, Network.GRPC.HighLevel.Generated.serverMaxReceiveMessageLength = Nothing
} }
withGRPCClient :: ClientConfig -> (Client -> IO a) -> IO a withGRPCClient :: ClientConfig -> (Client -> IO a) -> IO a

View file

@ -13,6 +13,7 @@ import Control.Monad
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy as BL
import Network.GRPC.LowLevel import Network.GRPC.LowLevel
import Numeric.Natural
import Proto3.Suite.Class import Proto3.Suite.Class
import System.IO import System.IO
@ -225,6 +226,7 @@ data ServerOptions = ServerOptions
-- ^ Security configuration. -- ^ Security configuration.
, optLogger :: String -> IO () , optLogger :: String -> IO ()
-- ^ Logging function to use to log errors in handling calls. -- ^ Logging function to use to log errors in handling calls.
, optMaxReceiveMessageLength :: Maybe Natural
} }
defaultOptions :: ServerOptions defaultOptions :: ServerOptions
@ -241,6 +243,7 @@ defaultOptions = ServerOptions
, optInitialMetadata = mempty , optInitialMetadata = mempty
, optSSLConfig = Nothing , optSSLConfig = Nothing
, optLogger = hPutStrLn stderr , optLogger = hPutStrLn stderr
, optMaxReceiveMessageLength = Nothing
} }
serverLoop :: ServerOptions -> IO () serverLoop :: ServerOptions -> IO ()

View file

@ -122,5 +122,7 @@ serverLoop ServerOptions{..} =
[ UserAgentPrefix optUserAgentPrefix [ UserAgentPrefix optUserAgentPrefix
, UserAgentSuffix optUserAgentSuffix , UserAgentSuffix optUserAgentSuffix
] ]
++
foldMap (pure . MaxReceiveMessageLength) optMaxReceiveMessageLength
, sslConfig = optSSLConfig , sslConfig = optSSLConfig
} }