-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | A web server for the Snap Framework
--   
--   Snap is a simple and fast web development framework and server written
--   in Haskell. For more information or to download the latest version,
--   you can visit the Snap project website at
--   http://snapframework.com/.
--   
--   The Snap HTTP server is a high performance web server library written
--   in Haskell. Together with the snap-core library upon which it
--   depends, it provides a clean and efficient Haskell programming
--   interface to the HTTP protocol.
@package snap-server
@version 1.1.2.1

-- | This module exports the Config datatype, which you can use to
--   configure the Snap HTTP server.
module Snap.Internal.Http.Server.Config

-- | Data type representing the configuration of a logging target
data ConfigLog

-- | no logging
ConfigNoLog :: ConfigLog

-- | log to text file
ConfigFileLog :: FilePath -> ConfigLog

-- | log custom IO handler
ConfigIoLog :: (ByteString -> IO ()) -> ConfigLog

-- | A record type which represents partial configurations (for
--   httpServe) by wrapping all of its fields in a Maybe.
--   Values of this type are usually constructed via its Monoid
--   instance by doing something like:
--   
--   
--   setPort 1234 mempty
--   
--   
--   Any fields which are unspecified in the Config passed to
--   httpServe (and this is the norm) are filled in with default
--   values from defaultConfig.
data Config (m :: Type -> Type) a
Config :: Maybe ByteString -> Maybe ConfigLog -> Maybe ConfigLog -> Maybe String -> Maybe Int -> Maybe ByteString -> Maybe Int -> Maybe ByteString -> Maybe FilePath -> Maybe Bool -> Maybe FilePath -> Maybe FilePath -> Maybe Int -> Maybe Bool -> Maybe Bool -> Maybe (SomeException -> m ()) -> Maybe Int -> Maybe a -> Maybe ProxyType -> Maybe (StartupInfo m a -> IO ()) -> Config (m :: Type -> Type) a
[hostname] :: Config (m :: Type -> Type) a -> Maybe ByteString
[accessLog] :: Config (m :: Type -> Type) a -> Maybe ConfigLog
[errorLog] :: Config (m :: Type -> Type) a -> Maybe ConfigLog
[locale] :: Config (m :: Type -> Type) a -> Maybe String
[port] :: Config (m :: Type -> Type) a -> Maybe Int
[bind] :: Config (m :: Type -> Type) a -> Maybe ByteString
[sslport] :: Config (m :: Type -> Type) a -> Maybe Int
[sslbind] :: Config (m :: Type -> Type) a -> Maybe ByteString
[sslcert] :: Config (m :: Type -> Type) a -> Maybe FilePath
[sslchaincert] :: Config (m :: Type -> Type) a -> Maybe Bool
[sslkey] :: Config (m :: Type -> Type) a -> Maybe FilePath
[unixsocket] :: Config (m :: Type -> Type) a -> Maybe FilePath
[unixaccessmode] :: Config (m :: Type -> Type) a -> Maybe Int
[compression] :: Config (m :: Type -> Type) a -> Maybe Bool
[verbose] :: Config (m :: Type -> Type) a -> Maybe Bool
[errorHandler] :: Config (m :: Type -> Type) a -> Maybe (SomeException -> m ())
[defaultTimeout] :: Config (m :: Type -> Type) a -> Maybe Int
[other] :: Config (m :: Type -> Type) a -> Maybe a
[proxyType] :: Config (m :: Type -> Type) a -> Maybe ProxyType
[startupHook] :: Config (m :: Type -> Type) a -> Maybe (StartupInfo m a -> IO ())

-- | FIXME
--   
--   Note: this type changed in snap-server 1.0.0.0.
data ProxyType
NoProxy :: ProxyType
HaProxy :: ProxyType
X_Forwarded_For :: ProxyType

-- | Returns a completely empty Config. Equivalent to mempty
--   from Config's Monoid instance.
emptyConfig :: forall (m :: Type -> Type) a. Config m a

-- | These are the default values for the options
defaultConfig :: forall (m :: Type -> Type) a. MonadSnap m => Config m a

-- | Returns a Config obtained from parsing command-line options,
--   using the default Snap OptDescr set.
--   
--   On Unix systems, the locale is read from the LANG environment
--   variable.
commandLineConfig :: forall (m :: Type -> Type) a. MonadSnap m => Config m a -> IO (Config m a)

-- | Returns a Config obtained from parsing command-line options,
--   using the default Snap OptDescr set as well as a list of user
--   OptDescrs. User OptDescrs use the "other" field (accessible using
--   getOther and setOther) to store additional command-line
--   option state. These are combined using a user-defined combining
--   function.
--   
--   On Unix systems, the locale is read from the LANG environment
--   variable.
extendedCommandLineConfig :: forall (m :: Type -> Type) a. MonadSnap m => [OptDescr (Maybe (Config m a))] -> (a -> a -> a) -> Config m a -> IO (Config m a)
completeConfig :: forall (m :: Type -> Type) a. MonadSnap m => Config m a -> IO (Config m a)

-- | Returns a description of the snap command line options suitable for
--   use with System.Console.GetOpt.
optDescrs :: forall (m :: Type -> Type) a. MonadSnap m => Config m a -> [OptDescr (Maybe (Config m a))]
fmapOpt :: (a -> b) -> OptDescr a -> OptDescr b

-- | Path to the access log
getAccessLog :: forall (m :: Type -> Type) a. Config m a -> Maybe ConfigLog

-- | Returns the address to bind to (for http)
getBind :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString

-- | If set and set to True, compression is turned on when applicable
getCompression :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool
getDefaultTimeout :: forall (m :: Type -> Type) a. Config m a -> Maybe Int

-- | A MonadSnap action to handle 500 errors
getErrorHandler :: Config m a -> Maybe (SomeException -> m ())

-- | Path to the error log
getErrorLog :: forall (m :: Type -> Type) a. Config m a -> Maybe ConfigLog

-- | The hostname of the HTTP server. This field has the same format as an
--   HTTP Host header; if a Host header came in with the
--   request, we use that, otherwise we default to this value specified in
--   the configuration.
getHostname :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString

-- | Gets the locale to use. Locales are used on Unix only, to set the
--   LANG/LC_ALL/etc. environment variable. For instance
--   if you set the locale to "en_US", we'll set the relevant
--   environment variables to "en_US.UTF-8".
getLocale :: forall (m :: Type -> Type) a. Config m a -> Maybe String
getOther :: forall (m :: Type -> Type) a. Config m a -> Maybe a

-- | Returns the port to listen on (for http)
getPort :: forall (m :: Type -> Type) a. Config m a -> Maybe Int
getProxyType :: forall (m :: Type -> Type) a. Config m a -> Maybe ProxyType

-- | Returns the address to bind to (for https)
getSSLBind :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString

-- | Path to the SSL certificate file
getSSLCert :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath

-- | Path to the SSL certificate file
getSSLChainCert :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool

-- | Path to the SSL key file
getSSLKey :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath

-- | Returns the port to listen on (for https)
getSSLPort :: forall (m :: Type -> Type) a. Config m a -> Maybe Int

-- | Whether to write server status updates to stderr
getVerbose :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool

-- | A startup hook is run after the server initializes but before user
--   request processing begins. The server passes, through a
--   StartupInfo object, the startup hook a list of the sockets it
--   is listening on and the final Config object completed after
--   command-line processing.
getStartupHook :: forall (m :: Type -> Type) a. Config m a -> Maybe (StartupInfo m a -> IO ())

-- | File path to unix socket. Must be absolute path, but allows for
--   symbolic links.
getUnixSocket :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath

-- | Access mode for unix socket, by default is system specific. This
--   should only be used to grant additional permissions to created socket
--   file, and not to remove permissions set by default. The only portable
--   way to limit access to socket is creating it in a directory with
--   proper permissions set.
--   
--   Most BSD systems ignore access permissions on unix sockets.
--   
--   Note: This uses umask. There is a race condition if process creates
--   other files at the same time as opening a unix socket with this option
--   set.
getUnixSocketAccessMode :: forall (m :: Type -> Type) a. Config m a -> Maybe Int
setAccessLog :: forall (m :: Type -> Type) a. ConfigLog -> Config m a -> Config m a
setBind :: forall (m :: Type -> Type) a. ByteString -> Config m a -> Config m a
setCompression :: forall (m :: Type -> Type) a. Bool -> Config m a -> Config m a
setDefaultTimeout :: forall (m :: Type -> Type) a. Int -> Config m a -> Config m a
setErrorHandler :: (SomeException -> m ()) -> Config m a -> Config m a
setErrorLog :: forall (m :: Type -> Type) a. ConfigLog -> Config m a -> Config m a
setHostname :: forall (m :: Type -> Type) a. ByteString -> Config m a -> Config m a
setLocale :: forall (m :: Type -> Type) a. String -> Config m a -> Config m a
setOther :: forall a (m :: Type -> Type). a -> Config m a -> Config m a
setPort :: forall (m :: Type -> Type) a. Int -> Config m a -> Config m a
setProxyType :: forall (m :: Type -> Type) a. ProxyType -> Config m a -> Config m a
setSSLBind :: forall (m :: Type -> Type) a. ByteString -> Config m a -> Config m a
setSSLCert :: forall (m :: Type -> Type) a. FilePath -> Config m a -> Config m a
setSSLChainCert :: forall (m :: Type -> Type) a. Bool -> Config m a -> Config m a
setSSLKey :: forall (m :: Type -> Type) a. FilePath -> Config m a -> Config m a
setSSLPort :: forall (m :: Type -> Type) a. Int -> Config m a -> Config m a
setVerbose :: forall (m :: Type -> Type) a. Bool -> Config m a -> Config m a
setUnixSocket :: forall (m :: Type -> Type) a. FilePath -> Config m a -> Config m a
setUnixSocketAccessMode :: forall (m :: Type -> Type) a. Int -> Config m a -> Config m a
setStartupHook :: forall (m :: Type -> Type) a. (StartupInfo m a -> IO ()) -> Config m a -> Config m a

-- | Arguments passed to setStartupHook.
data StartupInfo (m :: Type -> Type) a
StartupInfo :: Config m a -> [Socket] -> StartupInfo (m :: Type -> Type) a
[startupHookConfig] :: StartupInfo (m :: Type -> Type) a -> Config m a
[startupHookSockets] :: StartupInfo (m :: Type -> Type) a -> [Socket]

-- | The Sockets opened by the server. There will be two
--   Sockets for SSL connections, and one otherwise.
getStartupSockets :: forall (m :: Type -> Type) a. StartupInfo m a -> [Socket]
getStartupConfig :: forall (m :: Type -> Type) a. StartupInfo m a -> Config m a
emptyStartupInfo :: forall (m :: Type -> Type) a. StartupInfo m a
setStartupSockets :: forall (m :: Type -> Type) a. [Socket] -> StartupInfo m a -> StartupInfo m a
setStartupConfig :: forall (m :: Type -> Type) a. Config m a -> StartupInfo m a -> StartupInfo m a
instance GHC.Classes.Eq Snap.Internal.Http.Server.Config.ProxyType
instance GHC.Internal.Base.Monoid (Snap.Internal.Http.Server.Config.Config m a)
instance GHC.Internal.Base.Semigroup (Snap.Internal.Http.Server.Config.Config m a)
instance GHC.Internal.Show.Show (Snap.Internal.Http.Server.Config.Config m a)
instance GHC.Internal.Show.Show Snap.Internal.Http.Server.Config.ConfigLog
instance GHC.Internal.Show.Show Snap.Internal.Http.Server.Config.ProxyType

-- | This module exports the Config datatype, which you can use to
--   configure the Snap HTTP server.
module Snap.Http.Server.Config

-- | A record type which represents partial configurations (for
--   httpServe) by wrapping all of its fields in a Maybe.
--   Values of this type are usually constructed via its Monoid
--   instance by doing something like:
--   
--   
--   setPort 1234 mempty
--   
--   
--   Any fields which are unspecified in the Config passed to
--   httpServe (and this is the norm) are filled in with default
--   values from defaultConfig.
data Config (m :: Type -> Type) a

-- | Data type representing the configuration of a logging target
data ConfigLog

-- | no logging
ConfigNoLog :: ConfigLog

-- | log to text file
ConfigFileLog :: FilePath -> ConfigLog

-- | log custom IO handler
ConfigIoLog :: (ByteString -> IO ()) -> ConfigLog

-- | FIXME
--   
--   Note: this type changed in snap-server 1.0.0.0.
data ProxyType

-- | Returns a completely empty Config. Equivalent to mempty
--   from Config's Monoid instance.
emptyConfig :: forall (m :: Type -> Type) a. Config m a

-- | These are the default values for the options
defaultConfig :: forall (m :: Type -> Type) a. MonadSnap m => Config m a

-- | Returns a Config obtained from parsing command-line options,
--   using the default Snap OptDescr set.
--   
--   On Unix systems, the locale is read from the LANG environment
--   variable.
commandLineConfig :: forall (m :: Type -> Type) a. MonadSnap m => Config m a -> IO (Config m a)

-- | Returns a Config obtained from parsing command-line options,
--   using the default Snap OptDescr set as well as a list of user
--   OptDescrs. User OptDescrs use the "other" field (accessible using
--   getOther and setOther) to store additional command-line
--   option state. These are combined using a user-defined combining
--   function.
--   
--   On Unix systems, the locale is read from the LANG environment
--   variable.
extendedCommandLineConfig :: forall (m :: Type -> Type) a. MonadSnap m => [OptDescr (Maybe (Config m a))] -> (a -> a -> a) -> Config m a -> IO (Config m a)
completeConfig :: forall (m :: Type -> Type) a. MonadSnap m => Config m a -> IO (Config m a)

-- | Returns a description of the snap command line options suitable for
--   use with System.Console.GetOpt.
optDescrs :: forall (m :: Type -> Type) a. MonadSnap m => Config m a -> [OptDescr (Maybe (Config m a))]
fmapOpt :: (a -> b) -> OptDescr a -> OptDescr b

-- | Path to the access log
getAccessLog :: forall (m :: Type -> Type) a. Config m a -> Maybe ConfigLog

-- | Returns the address to bind to (for http)
getBind :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString

-- | If set and set to True, compression is turned on when applicable
getCompression :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool
getDefaultTimeout :: forall (m :: Type -> Type) a. Config m a -> Maybe Int

-- | A MonadSnap action to handle 500 errors
getErrorHandler :: Config m a -> Maybe (SomeException -> m ())

-- | Path to the error log
getErrorLog :: forall (m :: Type -> Type) a. Config m a -> Maybe ConfigLog

-- | The hostname of the HTTP server. This field has the same format as an
--   HTTP Host header; if a Host header came in with the
--   request, we use that, otherwise we default to this value specified in
--   the configuration.
getHostname :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString

-- | Gets the locale to use. Locales are used on Unix only, to set the
--   LANG/LC_ALL/etc. environment variable. For instance
--   if you set the locale to "en_US", we'll set the relevant
--   environment variables to "en_US.UTF-8".
getLocale :: forall (m :: Type -> Type) a. Config m a -> Maybe String
getOther :: forall (m :: Type -> Type) a. Config m a -> Maybe a

-- | Returns the port to listen on (for http)
getPort :: forall (m :: Type -> Type) a. Config m a -> Maybe Int
getProxyType :: forall (m :: Type -> Type) a. Config m a -> Maybe ProxyType

-- | Returns the address to bind to (for https)
getSSLBind :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString

-- | Path to the SSL certificate file
getSSLCert :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath

-- | Path to the SSL key file
getSSLKey :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath

-- | Path to the SSL certificate file
getSSLChainCert :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool

-- | Returns the port to listen on (for https)
getSSLPort :: forall (m :: Type -> Type) a. Config m a -> Maybe Int

-- | Whether to write server status updates to stderr
getVerbose :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool

-- | A startup hook is run after the server initializes but before user
--   request processing begins. The server passes, through a
--   StartupInfo object, the startup hook a list of the sockets it
--   is listening on and the final Config object completed after
--   command-line processing.
getStartupHook :: forall (m :: Type -> Type) a. Config m a -> Maybe (StartupInfo m a -> IO ())

-- | File path to unix socket. Must be absolute path, but allows for
--   symbolic links.
getUnixSocket :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath

-- | Access mode for unix socket, by default is system specific. This
--   should only be used to grant additional permissions to created socket
--   file, and not to remove permissions set by default. The only portable
--   way to limit access to socket is creating it in a directory with
--   proper permissions set.
--   
--   Most BSD systems ignore access permissions on unix sockets.
--   
--   Note: This uses umask. There is a race condition if process creates
--   other files at the same time as opening a unix socket with this option
--   set.
getUnixSocketAccessMode :: forall (m :: Type -> Type) a. Config m a -> Maybe Int
setAccessLog :: forall (m :: Type -> Type) a. ConfigLog -> Config m a -> Config m a
setBind :: forall (m :: Type -> Type) a. ByteString -> Config m a -> Config m a
setCompression :: forall (m :: Type -> Type) a. Bool -> Config m a -> Config m a
setDefaultTimeout :: forall (m :: Type -> Type) a. Int -> Config m a -> Config m a
setErrorHandler :: (SomeException -> m ()) -> Config m a -> Config m a
setErrorLog :: forall (m :: Type -> Type) a. ConfigLog -> Config m a -> Config m a
setHostname :: forall (m :: Type -> Type) a. ByteString -> Config m a -> Config m a
setLocale :: forall (m :: Type -> Type) a. String -> Config m a -> Config m a
setOther :: forall a (m :: Type -> Type). a -> Config m a -> Config m a
setPort :: forall (m :: Type -> Type) a. Int -> Config m a -> Config m a
setProxyType :: forall (m :: Type -> Type) a. ProxyType -> Config m a -> Config m a
setSSLBind :: forall (m :: Type -> Type) a. ByteString -> Config m a -> Config m a
setSSLCert :: forall (m :: Type -> Type) a. FilePath -> Config m a -> Config m a
setSSLKey :: forall (m :: Type -> Type) a. FilePath -> Config m a -> Config m a
setSSLChainCert :: forall (m :: Type -> Type) a. Bool -> Config m a -> Config m a
setSSLPort :: forall (m :: Type -> Type) a. Int -> Config m a -> Config m a
setVerbose :: forall (m :: Type -> Type) a. Bool -> Config m a -> Config m a
setUnixSocket :: forall (m :: Type -> Type) a. FilePath -> Config m a -> Config m a
setUnixSocketAccessMode :: forall (m :: Type -> Type) a. Int -> Config m a -> Config m a
setStartupHook :: forall (m :: Type -> Type) a. (StartupInfo m a -> IO ()) -> Config m a -> Config m a

-- | Arguments passed to setStartupHook.
data StartupInfo (m :: Type -> Type) a

-- | The Sockets opened by the server. There will be two
--   Sockets for SSL connections, and one otherwise.
getStartupSockets :: forall (m :: Type -> Type) a. StartupInfo m a -> [Socket]
getStartupConfig :: forall (m :: Type -> Type) a. StartupInfo m a -> Config m a

-- | Configure Snap in direct / non-proxying mode.
noProxy :: ProxyType

-- | Assert that Snap is running behind an HTTP proxy, and that the proxied
--   connection information will be stored in the "X-Forwarded-For" or
--   "Forwarded-For" HTTP headers.
xForwardedFor :: ProxyType

-- | Assert that Snap is running behind a proxy running the HaProxy
--   protocol (see
--   http://haproxy.1wt.eu/download/1.5/doc/proxy-protocol.txt). In
--   this mode connections that don't obey the proxy protocol are rejected.
haProxy :: ProxyType

-- | Types internal to the implementation of the Snap HTTP server.
module Snap.Internal.Http.Server.Types

-- | Data and services that all HTTP response handlers share.
data ServerConfig hookState
ServerConfig :: !Request -> Response -> Word64 -> IO () -> !Builder -> IO () -> !NewRequestHook hookState -> !ParseHook hookState -> !UserHandlerFinishedHook hookState -> !DataFinishedHook hookState -> !ExceptionHook hookState -> !EscapeSnapHook hookState -> !ByteString -> {-# UNPACK #-} !Int -> !Bool -> {-# UNPACK #-} !Int -> ServerConfig hookState
[_logAccess] :: ServerConfig hookState -> !Request -> Response -> Word64 -> IO ()
[_logError] :: ServerConfig hookState -> !Builder -> IO ()
[_onNewRequest] :: ServerConfig hookState -> !NewRequestHook hookState
[_onParse] :: ServerConfig hookState -> !ParseHook hookState
[_onUserHandlerFinished] :: ServerConfig hookState -> !UserHandlerFinishedHook hookState
[_onDataFinished] :: ServerConfig hookState -> !DataFinishedHook hookState
[_onException] :: ServerConfig hookState -> !ExceptionHook hookState
[_onEscape] :: ServerConfig hookState -> !EscapeSnapHook hookState

-- | will be overridden by a Host header if it appears.
[_localHostname] :: ServerConfig hookState -> !ByteString
[_defaultTimeout] :: ServerConfig hookState -> {-# UNPACK #-} !Int
[_isSecure] :: ServerConfig hookState -> !Bool

-- | Number of accept loops to spawn.
[_numAcceptLoops] :: ServerConfig hookState -> {-# UNPACK #-} !Int

-- | All of the things a session needs to service a single HTTP request.
data PerSessionData
PerSessionData :: {-# UNPACK #-} !IORef Bool -> !(Int -> Int) -> IO () -> !IORef Bool -> !SendFileHandler -> !ByteString -> {-# UNPACK #-} !Int -> !ByteString -> {-# UNPACK #-} !Int -> !InputStream ByteString -> !OutputStream ByteString -> PerSessionData

-- | If the bool stored in this IORef becomes true, the server will close
--   the connection after the current request is processed.
[_forceConnectionClose] :: PerSessionData -> {-# UNPACK #-} !IORef Bool

-- | An IO action to modify the current request timeout.
[_twiddleTimeout] :: PerSessionData -> !(Int -> Int) -> IO ()

-- | The value stored in this IORef is True if this request is the first on
--   a new connection, and False if it is a subsequent keep-alive request.
[_isNewConnection] :: PerSessionData -> !IORef Bool

-- | The function called when we want to use sendfile().
[_sendfileHandler] :: PerSessionData -> !SendFileHandler

-- | The server's idea of its local address.
[_localAddress] :: PerSessionData -> !ByteString

-- | The listening port number.
[_localPort] :: PerSessionData -> {-# UNPACK #-} !Int

-- | The address of the remote user.
[_remoteAddress] :: PerSessionData -> !ByteString

-- | The remote user's port.
[_remotePort] :: PerSessionData -> {-# UNPACK #-} !Int

-- | The read end of the socket connection.
[_readEnd] :: PerSessionData -> !InputStream ByteString

-- | The write end of the socket connection.
[_writeEnd] :: PerSessionData -> !OutputStream ByteString

-- | The DataFinishedHook is called once the server has finished
--   sending the HTTP response to the client.
type DataFinishedHook hookState = IORef hookState -> Request -> Response -> IO ()

-- | The EscapeSnapHook is called if the user handler escapes the
--   HTTP session, e.g. for websockets.
type EscapeSnapHook hookState = IORef hookState -> IO ()

-- | The ExceptionHook is called if an exception reaches the
--   toplevel of the server, i.e. if an exception leaks out of the user
--   handler or if an exception is raised during the sending of the HTTP
--   response data.
type ExceptionHook hookState = IORef hookState -> SomeException -> IO ()

-- | The ParseHook is called after the HTTP Request has been parsed
--   by the server, but before the user handler starts running.
type ParseHook hookState = IORef hookState -> Request -> IO ()

-- | The NewRequestHook is called once processing for an HTTP
--   request begins, i.e. after the connection has been accepted and we
--   know that there's data available to read from the socket. The IORef
--   passed to the hook initially contains a bottom value that will throw
--   an exception if evaluated.
type NewRequestHook hookState = PerSessionData -> IO hookState

-- | The UserHandlerFinishedHook is called once the user handler has
--   finished running, but before the data for the HTTP response starts
--   being sent to the client.
type UserHandlerFinishedHook hookState = IORef hookState -> Request -> Response -> IO ()

-- | A SendFileHandler is called if the user handler requests that a
--   file be sent using sendfile() on systems that support it
--   (Linux, Mac OSX, and FreeBSD).
type SendFileHandler = Buffer -> Builder -> FilePath -> Word64 -> Word64 -> IO ()

-- | This function, provided to the web server internals from the outside,
--   is responsible for producing a Response once the server has
--   parsed the Request.
type ServerHandler hookState = ServerConfig hookState -> PerSessionData -> Request -> IO (Request, Response)
newtype AcceptFunc
AcceptFunc :: ((forall a. () => IO a -> IO a) -> IO (SendFileHandler, ByteString, Int, ByteString, Int, InputStream ByteString, OutputStream ByteString, IO ())) -> AcceptFunc
[runAcceptFunc] :: AcceptFunc -> (forall a. () => IO a -> IO a) -> IO (SendFileHandler, ByteString, Int, ByteString, Int, InputStream ByteString, OutputStream ByteString, IO ())

-- | Either the server should start listening on the given interface / port
--   combination, or the server should start up with a Socket that
--   has already had bind() and listen() called on it.
data SocketConfig
StartListening :: ByteString -> Int -> SocketConfig
PreBound :: Socket -> SocketConfig

-- | Types used by the Snap HTTP Server.
module Snap.Http.Server.Types

-- | Data and services that all HTTP response handlers share.
data ServerConfig hookState

-- | All of the things a session needs to service a single HTTP request.
data PerSessionData
emptyServerConfig :: ServerConfig a
getDefaultTimeout :: ServerConfig hookState -> Int
getIsSecure :: ServerConfig hookState -> Bool
getLocalHostname :: ServerConfig hookState -> ByteString
getLogAccess :: ServerConfig hookState -> Request -> Response -> Word64 -> IO ()
getLogError :: ServerConfig hookState -> Builder -> IO ()
getNumAcceptLoops :: ServerConfig hookState -> Int
getOnDataFinished :: ServerConfig hookState -> DataFinishedHook hookState
getOnEscape :: ServerConfig hookState -> EscapeSnapHook hookState
getOnException :: ServerConfig hookState -> ExceptionHook hookState
getOnNewRequest :: ServerConfig hookState -> NewRequestHook hookState
getOnParse :: ServerConfig hookState -> ParseHook hookState
getOnUserHandlerFinished :: ServerConfig hookState -> UserHandlerFinishedHook hookState
setDefaultTimeout :: Int -> ServerConfig hookState -> ServerConfig hookState
setIsSecure :: Bool -> ServerConfig hookState -> ServerConfig hookState
setLocalHostname :: ByteString -> ServerConfig hookState -> ServerConfig hookState
setLogAccess :: (Request -> Response -> Word64 -> IO ()) -> ServerConfig hookState -> ServerConfig hookState
setLogError :: (Builder -> IO ()) -> ServerConfig hookState -> ServerConfig hookState
setNumAcceptLoops :: Int -> ServerConfig hookState -> ServerConfig hookState
setOnDataFinished :: DataFinishedHook hookState -> ServerConfig hookState -> ServerConfig hookState
setOnEscape :: EscapeSnapHook hookState -> ServerConfig hookState -> ServerConfig hookState
setOnException :: ExceptionHook hookState -> ServerConfig hookState -> ServerConfig hookState
setOnNewRequest :: NewRequestHook hookState -> ServerConfig hookState -> ServerConfig hookState
setOnParse :: ParseHook hookState -> ServerConfig hookState -> ServerConfig hookState
setOnUserHandlerFinished :: UserHandlerFinishedHook hookState -> ServerConfig hookState -> ServerConfig hookState
getTwiddleTimeout :: PerSessionData -> (Int -> Int) -> IO ()
isNewConnection :: PerSessionData -> IO Bool
getLocalAddress :: PerSessionData -> ByteString
getLocalPort :: PerSessionData -> Int
getRemoteAddress :: PerSessionData -> ByteString
getRemotePort :: PerSessionData -> Int

-- | The DataFinishedHook is called once the server has finished
--   sending the HTTP response to the client.
type DataFinishedHook hookState = IORef hookState -> Request -> Response -> IO ()

-- | The EscapeSnapHook is called if the user handler escapes the
--   HTTP session, e.g. for websockets.
type EscapeSnapHook hookState = IORef hookState -> IO ()

-- | The ExceptionHook is called if an exception reaches the
--   toplevel of the server, i.e. if an exception leaks out of the user
--   handler or if an exception is raised during the sending of the HTTP
--   response data.
type ExceptionHook hookState = IORef hookState -> SomeException -> IO ()

-- | The ParseHook is called after the HTTP Request has been parsed
--   by the server, but before the user handler starts running.
type ParseHook hookState = IORef hookState -> Request -> IO ()

-- | The NewRequestHook is called once processing for an HTTP
--   request begins, i.e. after the connection has been accepted and we
--   know that there's data available to read from the socket. The IORef
--   passed to the hook initially contains a bottom value that will throw
--   an exception if evaluated.
type NewRequestHook hookState = PerSessionData -> IO hookState

-- | The UserHandlerFinishedHook is called once the user handler has
--   finished running, but before the data for the HTTP response starts
--   being sent to the client.
type UserHandlerFinishedHook hookState = IORef hookState -> Request -> Response -> IO ()

-- | A SendFileHandler is called if the user handler requests that a
--   file be sent using sendfile() on systems that support it
--   (Linux, Mac OSX, and FreeBSD).
type SendFileHandler = Buffer -> Builder -> FilePath -> Word64 -> Word64 -> IO ()

-- | This function, provided to the web server internals from the outside,
--   is responsible for producing a Response once the server has
--   parsed the Request.
type ServerHandler hookState = ServerConfig hookState -> PerSessionData -> Request -> IO (Request, Response)
data AcceptFunc

-- | Either the server should start listening on the given interface / port
--   combination, or the server should start up with a Socket that
--   has already had bind() and listen() called on it.
data SocketConfig
StartListening :: ByteString -> Int -> SocketConfig
PreBound :: Socket -> SocketConfig

module System.FastLogger

-- | Holds the state for a logger.
data Logger

-- | Prepares a log message with the time prepended.
timestampedLogEntry :: ByteString -> IO ByteString

-- | Prepares a log message in "combined" format.
combinedLogEntry :: ByteString -> Maybe ByteString -> ByteString -> Int -> Word64 -> Maybe ByteString -> ByteString -> IO ByteString

-- | Creates a new logger, logging to the given file. If the file argument
--   is "-", then log to stdout; if it's "stderr" then we log to stderr,
--   otherwise we log to a regular file in append mode. The file is closed
--   and re-opened every 15 minutes to facilitate external log rotation.
newLogger :: FilePath -> IO Logger

-- | Like newLogger, but uses a custom error action if the logger
--   needs to print an error message of its own (for instance, if it can't
--   open the output file.)
newLoggerWithCustomErrorFunction :: (ByteString -> IO ()) -> FilePath -> IO Logger

-- | Creates a Logger and passes it into the given function, cleaning up
--   with "stopLogger" afterwards.
withLogger :: FilePath -> (Logger -> IO a) -> IO a

-- | Creates a Logger with "newLoggerWithCustomErrorFunction" and passes it
--   into the given function, cleaning up with "stopLogger" afterwards.
withLoggerWithCustomErrorFunction :: (ByteString -> IO ()) -> FilePath -> (Logger -> IO a) -> IO a

-- | Kills a logger thread, causing any unwritten contents to be flushed
--   out to disk
stopLogger :: Logger -> IO ()

-- | Sends out a log message verbatim with a newline appended. Note: if you
--   want a fancy log message you'll have to format it yourself (or use
--   combinedLogEntry).
logMsg :: Logger -> ByteString -> IO ()

-- | The Snap HTTP server is a high performance web server library written
--   in Haskell. Together with the snap-core library upon which it
--   depends, it provides a clean and efficient Haskell programming
--   interface to the HTTP protocol.
module Snap.Http.Server

-- | Starts serving HTTP requests using the given handler. This function
--   never returns; to shut down the HTTP server, kill the controlling
--   thread.
--   
--   This function is like httpServe except it doesn't setup
--   compression, reverse proxy address translation (via
--   behindProxy), or the error handler; this allows it to be used
--   from MonadSnap.
simpleHttpServe :: forall (m :: Type -> Type) a. MonadSnap m => Config m a -> Snap () -> IO ()

-- | Starts serving HTTP requests using the given handler, with settings
--   from the Config passed in. This function never returns; to shut
--   down the HTTP server, kill the controlling thread.
httpServe :: Config Snap a -> Snap () -> IO ()

-- | Starts serving HTTP using the given handler. The configuration is read
--   from the options given on the command-line, as returned by
--   commandLineConfig. This function never returns; to shut down
--   the HTTP server, kill the controlling thread.
quickHttpServe :: Snap () -> IO ()

-- | A short string describing the Snap server version
snapServerVersion :: ByteString

-- | Given a string like "en_US", this sets the locale to "en_US.UTF-8".
--   This doesn't work on Windows.
setUnicodeLocale :: String -> IO ()
rawHttpServe :: ServerHandler s -> ServerConfig s -> [AcceptFunc] -> IO ()
