{-# LANGUAGE CPP #-}
module Network.WebSockets.Connection.Options
( ConnectionOptions (..)
, defaultConnectionOptions
, CompressionOptions (..)
, PermessageDeflate (..)
, defaultPermessageDeflate
, SizeLimit (..)
, atMostSizeLimit
) where
import Data.Int (Int64)
import Data.Monoid (Monoid (..))
import Prelude
data ConnectionOptions = ConnectionOptions
{ ConnectionOptions -> IO ()
connectionOnPong :: !(IO ())
, ConnectionOptions -> CompressionOptions
connectionCompressionOptions :: !CompressionOptions
, ConnectionOptions -> Bool
connectionStrictUnicode :: !Bool
, ConnectionOptions -> SizeLimit
connectionFramePayloadSizeLimit :: !SizeLimit
, ConnectionOptions -> SizeLimit
connectionMessageDataSizeLimit :: !SizeLimit
}
defaultConnectionOptions :: ConnectionOptions
defaultConnectionOptions :: ConnectionOptions
defaultConnectionOptions = ConnectionOptions
{ connectionOnPong :: IO ()
connectionOnPong = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
, connectionCompressionOptions :: CompressionOptions
connectionCompressionOptions = CompressionOptions
NoCompression
, connectionStrictUnicode :: Bool
connectionStrictUnicode = Bool
False
, connectionFramePayloadSizeLimit :: SizeLimit
connectionFramePayloadSizeLimit = SizeLimit
forall a. Monoid a => a
mempty
, connectionMessageDataSizeLimit :: SizeLimit
connectionMessageDataSizeLimit = SizeLimit
forall a. Monoid a => a
mempty
}
data CompressionOptions
= NoCompression
| PermessageDeflateCompression PermessageDeflate
deriving (CompressionOptions -> CompressionOptions -> Bool
(CompressionOptions -> CompressionOptions -> Bool)
-> (CompressionOptions -> CompressionOptions -> Bool)
-> Eq CompressionOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CompressionOptions -> CompressionOptions -> Bool
== :: CompressionOptions -> CompressionOptions -> Bool
$c/= :: CompressionOptions -> CompressionOptions -> Bool
/= :: CompressionOptions -> CompressionOptions -> Bool
Eq, Int -> CompressionOptions -> ShowS
[CompressionOptions] -> ShowS
CompressionOptions -> String
(Int -> CompressionOptions -> ShowS)
-> (CompressionOptions -> String)
-> ([CompressionOptions] -> ShowS)
-> Show CompressionOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CompressionOptions -> ShowS
showsPrec :: Int -> CompressionOptions -> ShowS
$cshow :: CompressionOptions -> String
show :: CompressionOptions -> String
$cshowList :: [CompressionOptions] -> ShowS
showList :: [CompressionOptions] -> ShowS
Show)
data PermessageDeflate = PermessageDeflate
{ PermessageDeflate -> Bool
serverNoContextTakeover :: Bool
, PermessageDeflate -> Bool
clientNoContextTakeover :: Bool
, PermessageDeflate -> Int
serverMaxWindowBits :: Int
, PermessageDeflate -> Int
clientMaxWindowBits :: Int
, PermessageDeflate -> Int
pdCompressionLevel :: Int
} deriving (PermessageDeflate -> PermessageDeflate -> Bool
(PermessageDeflate -> PermessageDeflate -> Bool)
-> (PermessageDeflate -> PermessageDeflate -> Bool)
-> Eq PermessageDeflate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PermessageDeflate -> PermessageDeflate -> Bool
== :: PermessageDeflate -> PermessageDeflate -> Bool
$c/= :: PermessageDeflate -> PermessageDeflate -> Bool
/= :: PermessageDeflate -> PermessageDeflate -> Bool
Eq, Int -> PermessageDeflate -> ShowS
[PermessageDeflate] -> ShowS
PermessageDeflate -> String
(Int -> PermessageDeflate -> ShowS)
-> (PermessageDeflate -> String)
-> ([PermessageDeflate] -> ShowS)
-> Show PermessageDeflate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PermessageDeflate -> ShowS
showsPrec :: Int -> PermessageDeflate -> ShowS
$cshow :: PermessageDeflate -> String
show :: PermessageDeflate -> String
$cshowList :: [PermessageDeflate] -> ShowS
showList :: [PermessageDeflate] -> ShowS
Show)
defaultPermessageDeflate :: PermessageDeflate
defaultPermessageDeflate :: PermessageDeflate
defaultPermessageDeflate = Bool -> Bool -> Int -> Int -> Int -> PermessageDeflate
PermessageDeflate Bool
False Bool
False Int
15 Int
15 Int
8
data SizeLimit
= NoSizeLimit
| SizeLimit !Int64
deriving (SizeLimit -> SizeLimit -> Bool
(SizeLimit -> SizeLimit -> Bool)
-> (SizeLimit -> SizeLimit -> Bool) -> Eq SizeLimit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SizeLimit -> SizeLimit -> Bool
== :: SizeLimit -> SizeLimit -> Bool
$c/= :: SizeLimit -> SizeLimit -> Bool
/= :: SizeLimit -> SizeLimit -> Bool
Eq, Int -> SizeLimit -> ShowS
[SizeLimit] -> ShowS
SizeLimit -> String
(Int -> SizeLimit -> ShowS)
-> (SizeLimit -> String)
-> ([SizeLimit] -> ShowS)
-> Show SizeLimit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SizeLimit -> ShowS
showsPrec :: Int -> SizeLimit -> ShowS
$cshow :: SizeLimit -> String
show :: SizeLimit -> String
$cshowList :: [SizeLimit] -> ShowS
showList :: [SizeLimit] -> ShowS
Show)
instance Monoid SizeLimit where
mempty :: SizeLimit
mempty = SizeLimit
NoSizeLimit
#if !MIN_VERSION_base(4,11,0)
mappend NoSizeLimit y = y
mappend x NoSizeLimit = x
mappend (SizeLimit x) (SizeLimit y) = SizeLimit (min x y)
#else
instance Semigroup SizeLimit where
<> :: SizeLimit -> SizeLimit -> SizeLimit
(<>) SizeLimit
NoSizeLimit SizeLimit
y = SizeLimit
y
(<>) SizeLimit
x SizeLimit
NoSizeLimit = SizeLimit
x
(<>) (SizeLimit Int64
x) (SizeLimit Int64
y) = Int64 -> SizeLimit
SizeLimit (Int64 -> Int64 -> Int64
forall a. Ord a => a -> a -> a
min Int64
x Int64
y)
#endif
atMostSizeLimit :: Int64 -> SizeLimit -> Bool
atMostSizeLimit :: Int64 -> SizeLimit -> Bool
atMostSizeLimit Int64
_ SizeLimit
NoSizeLimit = Bool
True
atMostSizeLimit Int64
s (SizeLimit Int64
l) = Int64
s Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
l
{-# INLINE atMostSizeLimit #-}