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
version: 0.0.1.0
version: 0.0.1.1
synopsis: Haskell implementation of gRPC layered on shared C library.
homepage: https://github.com/awakenetworks/gRPC-haskell
license: Apache-2.0

View File

@ -42,6 +42,8 @@ import Network.GRPC.HighLevel.Server
import Network.GRPC.HighLevel.Client
import Network.GRPC.LowLevel
import Network.GRPC.LowLevel.Call
import qualified Network.GRPC.Unsafe.ChannelArgs as C
import Numeric.Natural
import System.IO (hPutStrLn, stderr)
-- | Used at the kind level as a parameter to service definitions
@ -78,6 +80,8 @@ data ServiceOptions = ServiceOptions
-- ^ Security configuration.
, logger :: String -> IO ()
-- ^ 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
@ -91,6 +95,7 @@ defaultServiceOptions = ServiceOptions
, Network.GRPC.HighLevel.Generated.initialMetadata = mempty
, Network.GRPC.HighLevel.Generated.sslConfig = Nothing
, Network.GRPC.HighLevel.Generated.logger = hPutStrLn stderr
, Network.GRPC.HighLevel.Generated.serverMaxReceiveMessageLength = Nothing
}
withGRPCClient :: ClientConfig -> (Client -> IO a) -> IO a

View File

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

View File

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