Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module exports the Config
datatype, which you can use to configure
the Snap HTTP server.
Synopsis
- data Config m a
- data ConfigLog
- = ConfigNoLog
- | ConfigFileLog FilePath
- | ConfigIoLog (ByteString -> IO ())
- data ProxyType
- emptyConfig :: Config m a
- defaultConfig :: MonadSnap m => Config m a
- commandLineConfig :: MonadSnap m => Config m a -> IO (Config m a)
- extendedCommandLineConfig :: MonadSnap m => [OptDescr (Maybe (Config m a))] -> (a -> a -> a) -> Config m a -> IO (Config m a)
- completeConfig :: MonadSnap m => Config m a -> IO (Config m a)
- optDescrs :: forall m a. MonadSnap m => Config m a -> [OptDescr (Maybe (Config m a))]
- fmapOpt :: (a -> b) -> OptDescr a -> OptDescr b
- getAccessLog :: Config m a -> Maybe ConfigLog
- getBind :: Config m a -> Maybe ByteString
- getCompression :: Config m a -> Maybe Bool
- getDefaultTimeout :: Config m a -> Maybe Int
- getErrorHandler :: Config m a -> Maybe (SomeException -> m ())
- getErrorLog :: Config m a -> Maybe ConfigLog
- getHostname :: Config m a -> Maybe ByteString
- getLocale :: Config m a -> Maybe String
- getOther :: Config m a -> Maybe a
- getPort :: Config m a -> Maybe Int
- getProxyType :: Config m a -> Maybe ProxyType
- getSSLBind :: Config m a -> Maybe ByteString
- getSSLCert :: Config m a -> Maybe FilePath
- getSSLKey :: Config m a -> Maybe FilePath
- getSSLChainCert :: Config m a -> Maybe Bool
- getSSLPort :: Config m a -> Maybe Int
- getVerbose :: Config m a -> Maybe Bool
- getStartupHook :: Config m a -> Maybe (StartupInfo m a -> IO ())
- getUnixSocket :: Config m a -> Maybe FilePath
- getUnixSocketAccessMode :: Config m a -> Maybe Int
- setAccessLog :: ConfigLog -> Config m a -> Config m a
- setBind :: ByteString -> Config m a -> Config m a
- setCompression :: Bool -> Config m a -> Config m a
- setDefaultTimeout :: Int -> Config m a -> Config m a
- setErrorHandler :: (SomeException -> m ()) -> Config m a -> Config m a
- setErrorLog :: ConfigLog -> Config m a -> Config m a
- setHostname :: ByteString -> Config m a -> Config m a
- setLocale :: String -> Config m a -> Config m a
- setOther :: a -> Config m a -> Config m a
- setPort :: Int -> Config m a -> Config m a
- setProxyType :: ProxyType -> Config m a -> Config m a
- setSSLBind :: ByteString -> Config m a -> Config m a
- setSSLCert :: FilePath -> Config m a -> Config m a
- setSSLKey :: FilePath -> Config m a -> Config m a
- setSSLChainCert :: Bool -> Config m a -> Config m a
- setSSLPort :: Int -> Config m a -> Config m a
- setVerbose :: Bool -> Config m a -> Config m a
- setUnixSocket :: FilePath -> Config m a -> Config m a
- setUnixSocketAccessMode :: Int -> Config m a -> Config m a
- setStartupHook :: (StartupInfo m a -> IO ()) -> Config m a -> Config m a
- data StartupInfo m a
- getStartupSockets :: StartupInfo m a -> [Socket]
- getStartupConfig :: StartupInfo m a -> Config m a
- noProxy :: ProxyType
- xForwardedFor :: ProxyType
- haProxy :: ProxyType
Documentation
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 type representing the configuration of a logging target
ConfigNoLog | no logging |
ConfigFileLog FilePath | log to text file |
ConfigIoLog (ByteString -> IO ()) | log custom IO handler |
FIXME
Note: this type changed in snap-server 1.0.0.0.
emptyConfig :: Config m a Source #
defaultConfig :: MonadSnap m => Config m a Source #
These are the default values for the options
:: MonadSnap m | |
=> Config m a | default configuration. This is combined with
|
-> IO (Config m a) |
extendedCommandLineConfig Source #
:: MonadSnap m | |
=> [OptDescr (Maybe (Config m a))] | Full list of command line options (combine
yours with |
-> (a -> a -> a) | State for multiple invoked user command-line options will be combined using this function. |
-> Config m a | default configuration. This is combined with
Snap's |
-> 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.
Returns a description of the snap command line options suitable for use with System.Console.GetOpt.
getCompression :: Config m a -> Maybe Bool Source #
If set and set to True, compression is turned on when applicable
getErrorHandler :: Config m a -> Maybe (SomeException -> m ()) Source #
A MonadSnap action to handle 500 errors
getHostname :: Config m a -> Maybe ByteString Source #
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.
getLocale :: Config m a -> Maybe String Source #
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
".
getSSLBind :: Config m a -> Maybe ByteString Source #
Returns the address to bind to (for https)
getStartupHook :: Config m a -> Maybe (StartupInfo m a -> IO ()) Source #
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.
getUnixSocket :: Config m a -> Maybe FilePath Source #
File path to unix socket. Must be absolute path, but allows for symbolic links.
getUnixSocketAccessMode :: Config m a -> Maybe Int Source #
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.
setErrorHandler :: (SomeException -> m ()) -> Config m a -> Config m a Source #
setHostname :: ByteString -> Config m a -> Config m a Source #
setSSLBind :: ByteString -> Config m a -> Config m a Source #
setStartupHook :: (StartupInfo m a -> IO ()) -> Config m a -> Config m a Source #
data StartupInfo m a Source #
Arguments passed to setStartupHook
.
getStartupSockets :: StartupInfo m a -> [Socket] Source #
getStartupConfig :: StartupInfo m a -> Config m a Source #
Proxy protocol selection
xForwardedFor :: ProxyType Source #
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.
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.