{-# LANGUAGE OverloadedStrings #-}
module Snap.Http.Server.Types
( ServerConfig
, PerSessionData
, emptyServerConfig
, getDefaultTimeout
, getIsSecure
, getLocalHostname
, getLogAccess
, getLogError
, getNumAcceptLoops
, getOnDataFinished
, getOnEscape
, getOnException
, getOnNewRequest
, getOnParse
, getOnUserHandlerFinished
, setDefaultTimeout
, setIsSecure
, setLocalHostname
, setLogAccess
, setLogError
, setNumAcceptLoops
, setOnDataFinished
, setOnEscape
, setOnException
, setOnNewRequest
, setOnParse
, setOnUserHandlerFinished
, getTwiddleTimeout
, isNewConnection
, getLocalAddress
, getLocalPort
, getRemoteAddress
, getRemotePort
, DataFinishedHook
, EscapeSnapHook
, ExceptionHook
, ParseHook
, NewRequestHook
, UserHandlerFinishedHook
, SendFileHandler
, ServerHandler
, AcceptFunc
, SocketConfig(..)
) where
import Data.ByteString (ByteString)
import Data.IORef (readIORef)
import Data.Word (Word64)
import Data.ByteString.Builder (Builder)
import Snap.Core (Request, Response)
import Snap.Internal.Http.Server.Types (AcceptFunc, DataFinishedHook, EscapeSnapHook, ExceptionHook, NewRequestHook, ParseHook, PerSessionData (_isNewConnection, _localAddress, _localPort, _remoteAddress, _remotePort, _twiddleTimeout), SendFileHandler, ServerConfig (..), ServerHandler, SocketConfig (..), UserHandlerFinishedHook)
emptyServerConfig :: ServerConfig a
emptyServerConfig =
ServerConfig (\_ _ _ -> return $! ())
(\_ -> return $! ())
(\_ -> return $ error "undefined hook state")
(\_ _ -> return $! ())
(\_ _ _ -> return $! ())
(\_ _ _ -> return $! ())
(\_ _ -> return $! ())
(\_ -> return $! ())
"localhost"
30
False
1
getLogAccess :: ServerConfig hookState -> Request -> Response -> Word64 -> IO ()
getLogAccess sc = _logAccess sc
getLogError :: ServerConfig hookState -> Builder -> IO ()
getLogError sc = _logError sc
getOnNewRequest :: ServerConfig hookState -> NewRequestHook hookState
getOnNewRequest sc = _onNewRequest sc
getOnParse :: ServerConfig hookState -> ParseHook hookState
getOnParse sc = _onParse sc
getOnUserHandlerFinished :: ServerConfig hookState
-> UserHandlerFinishedHook hookState
getOnUserHandlerFinished sc = _onUserHandlerFinished sc
getOnDataFinished :: ServerConfig hookState -> DataFinishedHook hookState
getOnDataFinished sc = _onDataFinished sc
getOnException :: ServerConfig hookState -> ExceptionHook hookState
getOnException sc = _onException sc
getOnEscape :: ServerConfig hookState -> EscapeSnapHook hookState
getOnEscape sc = _onEscape sc
getLocalHostname :: ServerConfig hookState -> ByteString
getLocalHostname sc = _localHostname sc
getDefaultTimeout :: ServerConfig hookState -> Int
getDefaultTimeout sc = _defaultTimeout sc
getIsSecure :: ServerConfig hookState -> Bool
getIsSecure sc = _isSecure sc
getNumAcceptLoops :: ServerConfig hookState -> Int
getNumAcceptLoops sc = _numAcceptLoops sc
setLogAccess :: (Request -> Response -> Word64 -> IO ())
-> ServerConfig hookState
-> ServerConfig hookState
setLogAccess s sc = sc { _logAccess = s }
setLogError :: (Builder -> IO ())
-> ServerConfig hookState
-> ServerConfig hookState
setLogError s sc = sc { _logError = s }
setOnNewRequest :: NewRequestHook hookState
-> ServerConfig hookState
-> ServerConfig hookState
setOnNewRequest s sc = sc { _onNewRequest = s }
setOnParse :: ParseHook hookState
-> ServerConfig hookState
-> ServerConfig hookState
setOnParse s sc = sc { _onParse = s }
setOnUserHandlerFinished :: UserHandlerFinishedHook hookState
-> ServerConfig hookState
-> ServerConfig hookState
setOnUserHandlerFinished s sc = sc { _onUserHandlerFinished = s }
setOnDataFinished :: DataFinishedHook hookState
-> ServerConfig hookState
-> ServerConfig hookState
setOnDataFinished s sc = sc { _onDataFinished = s }
setOnException :: ExceptionHook hookState
-> ServerConfig hookState
-> ServerConfig hookState
setOnException s sc = sc { _onException = s }
setOnEscape :: EscapeSnapHook hookState
-> ServerConfig hookState
-> ServerConfig hookState
setOnEscape s sc = sc { _onEscape = s }
setLocalHostname :: ByteString
-> ServerConfig hookState
-> ServerConfig hookState
setLocalHostname s sc = sc { _localHostname = s }
setDefaultTimeout :: Int -> ServerConfig hookState -> ServerConfig hookState
setDefaultTimeout s sc = sc { _defaultTimeout = s }
setIsSecure :: Bool -> ServerConfig hookState -> ServerConfig hookState
setIsSecure s sc = sc { _isSecure = s }
setNumAcceptLoops :: Int -> ServerConfig hookState -> ServerConfig hookState
setNumAcceptLoops s sc = sc { _numAcceptLoops = s }
getTwiddleTimeout :: PerSessionData -> ((Int -> Int) -> IO ())
getTwiddleTimeout psd = _twiddleTimeout psd
isNewConnection :: PerSessionData -> IO Bool
isNewConnection = readIORef . _isNewConnection
getLocalAddress :: PerSessionData -> ByteString
getLocalAddress psd = _localAddress psd
getLocalPort :: PerSessionData -> Int
getLocalPort psd = _localPort psd
getRemoteAddress :: PerSessionData -> ByteString
getRemoteAddress psd = _remoteAddress psd
getRemotePort :: PerSessionData -> Int
getRemotePort psd = _remotePort psd