snap-server-1.1.2.1: A web server for the Snap Framework

Safe Haskell | None
Language | Haskell2010

Snap.Http.Server.Config

Contents

- Proxy protocol selection

Description

This module exports the `Config` datatype, which you can use to configure the Snap HTTP server.

Synopsis

- data Config (m :: Type -> Type) a
- data ConfigLog
  - = ConfigNoLog
  - | ConfigFileLog FilePath
  - | ConfigIoLog (ByteString -> IO ())
- data ProxyType
- emptyConfig :: forall (m :: Type -> Type) a. Config m a
- defaultConfig :: forall (m :: Type -> Type) a. MonadSnap m => Config m a
- commandLineConfig :: forall (m :: Type -> Type) a. MonadSnap m => Config m a -> IO (Config m a)
- 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)
- optDescrs :: forall (m :: Type -> Type) a. MonadSnap m => Config m a -> [OptDescr (Maybe (Config m a))]
- fmapOpt :: (a -> b) -> OptDescr a -> OptDescr b
- getAccessLog :: forall (m :: Type -> Type) a. Config m a -> Maybe ConfigLog
- getBind :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString
- getCompression :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool
- getDefaultTimeout :: forall (m :: Type -> Type) a. Config m a -> Maybe Int
- getErrorHandler :: Config m a -> Maybe (SomeException -> m ())
- getErrorLog :: forall (m :: Type -> Type) a. Config m a -> Maybe ConfigLog
- getHostname :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString
- getLocale :: forall (m :: Type -> Type) a. Config m a -> Maybe String
- getOther :: forall (m :: Type -> Type) a. Config m a -> Maybe a
- getPort :: forall (m :: Type -> Type) a. Config m a -> Maybe Int
- getProxyType :: forall (m :: Type -> Type) a. Config m a -> Maybe ProxyType
- getSSLBind :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString
- getSSLCert :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath
- getSSLKey :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath
- getSSLChainCert :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool
- getSSLPort :: forall (m :: Type -> Type) a. Config m a -> Maybe Int
- getVerbose :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool
- getStartupHook :: forall (m :: Type -> Type) a. Config m a -> Maybe (StartupInfo m a -> IO ())
- getUnixSocket :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath
- 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
- data StartupInfo (m :: Type -> Type) a
- getStartupSockets :: forall (m :: Type -> Type) a. StartupInfo m a -> [Socket]
- getStartupConfig :: forall (m :: Type -> Type) a. StartupInfo m a -> Config m a
- noProxy :: ProxyType
- xForwardedFor :: ProxyType
- haProxy :: ProxyType

# Documentation

data Config (m :: Type -> Type) a #

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`.

#### Instances

Instances details

Monoid (Config m a) # |
Instance details Defined in Snap.Internal.Http.Server.Config Methods mempty :: Config m a # mappend :: Config m a -> Config m a -> Config m a # mconcat :: [Config m a] -> Config m a #
Semigroup (Config m a) # |
Instance details Defined in Snap.Internal.Http.Server.Config Methods (<>) :: Config m a -> Config m a -> Config m a # sconcat :: NonEmpty (Config m a) -> Config m a # stimes :: Integral b => b -> Config m a -> Config m a #
Show (Config m a) # |
Instance details Defined in Snap.Internal.Http.Server.Config Methods showsPrec :: Int -> Config m a -> ShowS # show :: Config m a -> String # showList :: [Config m a] -> ShowS #

data ConfigLog #

Data type representing the configuration of a logging target

Constructors

ConfigNoLog | no logging
ConfigFileLog FilePath | log to text file
ConfigIoLog (ByteString -> IO ()) | log custom IO handler

#### Instances

Instances details

Show ConfigLog # |
Instance details Defined in Snap.Internal.Http.Server.Config Methods showsPrec :: Int -> ConfigLog -> ShowS # show :: ConfigLog -> String # showList :: [ConfigLog] -> ShowS #

data ProxyType #

FIXME

Note: this type changed in snap-server 1.0.0.0.

#### Instances

Instances details

Show ProxyType # |
Instance details Defined in Snap.Internal.Http.Server.Config Methods showsPrec :: Int -> ProxyType -> ShowS # show :: ProxyType -> String # showList :: [ProxyType] -> ShowS #
Eq ProxyType # |
Instance details Defined in Snap.Internal.Http.Server.Config Methods (==) :: ProxyType -> ProxyType -> Bool # (/=) :: ProxyType -> ProxyType -> Bool #

emptyConfig :: forall (m :: Type -> Type) a. Config m a #

Returns a completely empty `Config`. Equivalent to `mempty` from `Config'`s `Monoid` instance.

defaultConfig :: forall (m :: Type -> Type) a. MonadSnap m => Config m a #

These are the default values for the options

commandLineConfig #

Arguments

:: forall (m :: Type -> Type) a. MonadSnap m |
=> Config m a | default configuration. This is combined with `defaultConfig` to obtain default values to use if the given parameter is specified on the command line. Usually it is fine to use `emptyConfig` here.
-> IO (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.

extendedCommandLineConfig #

Arguments

:: forall (m :: Type -> Type) a. MonadSnap m |
=> [OptDescr (Maybe (Config m a))] | Full list of command line options (combine yours with `optDescrs` to extend Snap's default set of options)
-> (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 `defaultConfig` to obtain default values to use if the given parameter is specified on the command line. Usually it is fine to use `emptyConfig` here.
-> 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.

completeConfig :: forall (m :: Type -> Type) a. MonadSnap m => Config m a -> IO (Config m a) #

optDescrs #

Arguments

:: forall (m :: Type -> Type) a. MonadSnap m |
=> Config m a | the configuration defaults.
-> [OptDescr (Maybe (Config m a))] |

Returns a description of the snap command line options suitable for use with System.Console.GetOpt.

fmapOpt :: (a -> b) -> OptDescr a -> OptDescr b #

getAccessLog :: forall (m :: Type -> Type) a. Config m a -> Maybe ConfigLog #

Path to the access log

getBind :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString #

Returns the address to bind to (for http)

getCompression :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool #

If set and set to True, compression is turned on when applicable

getDefaultTimeout :: forall (m :: Type -> Type) a. Config m a -> Maybe Int #

getErrorHandler :: Config m a -> Maybe (SomeException -> m ()) #

A MonadSnap action to handle 500 errors

getErrorLog :: forall (m :: Type -> Type) a. Config m a -> Maybe ConfigLog #

Path to the error log

getHostname :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString #

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 :: forall (m :: Type -> Type) a. Config m a -> Maybe String #

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`".

getOther :: forall (m :: Type -> Type) a. Config m a -> Maybe a #

getPort :: forall (m :: Type -> Type) a. Config m a -> Maybe Int #

Returns the port to listen on (for http)

getProxyType :: forall (m :: Type -> Type) a. Config m a -> Maybe ProxyType #

getSSLBind :: forall (m :: Type -> Type) a. Config m a -> Maybe ByteString #

Returns the address to bind to (for https)

getSSLCert :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath #

Path to the SSL certificate file

getSSLKey :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath #

Path to the SSL key file

getSSLChainCert :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool #

Path to the SSL certificate file

getSSLPort :: forall (m :: Type -> Type) a. Config m a -> Maybe Int #

Returns the port to listen on (for https)

getVerbose :: forall (m :: Type -> Type) a. Config m a -> Maybe Bool #

Whether to write server status updates to stderr

getStartupHook :: forall (m :: Type -> Type) a. Config m a -> Maybe (StartupInfo m a -> IO ()) #

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 :: forall (m :: Type -> Type) a. Config m a -> Maybe FilePath #

File path to unix socket. Must be absolute path, but allows for symbolic links.

getUnixSocketAccessMode :: forall (m :: Type -> Type) a. Config m a -> Maybe Int #

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.

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 #

data StartupInfo (m :: Type -> Type) a #

Arguments passed to `setStartupHook`.

getStartupSockets :: forall (m :: Type -> Type) a. StartupInfo m a -> [Socket] #

The `Socket`s opened by the server. There will be two `Socket`s for SSL connections, and one otherwise.

getStartupConfig :: forall (m :: Type -> Type) a. StartupInfo m a -> Config m a #

## Proxy protocol selection

noProxy :: ProxyType #

Configure Snap in direct / non-proxying mode.

xForwardedFor :: 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.

haProxy :: 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.