Network.Wai.Handler.Warp
Contents
Description
A fast, light-weight HTTP server handler for WAI. Some random notes (a FAQ, if you will):
- When a
ResponseFileindicates a file which does not exist, an exception is thrown. This will close the connection to the client as well. You should handle file existance checks at the application level.
- run :: Port -> Application -> IO ()
- runSettings :: Settings -> Application -> IO ()
- runSettingsSocket :: Settings -> Socket -> Application -> IO ()
- data Settings
- defaultSettings :: Settings
- settingsPort :: Settings -> Int
- settingsHost :: Settings -> String
- settingsOnException :: Settings -> SomeException -> IO ()
- settingsTimeout :: Settings -> Int
- settingsIntercept :: Settings -> Request -> Maybe (Socket -> Iteratee ByteString IO ())
- settingsManager :: Settings -> Maybe Manager
- type Port = Int
- data InvalidRequest
- data Manager
- withManager :: Int -> (Manager -> IO a) -> IO a
- parseRequest :: Port -> SockAddr -> Iteratee ByteString IO (Integer, Request)
- sendResponse :: Handle -> Request -> Socket -> Response -> IO Bool
- registerKillThread :: Manager -> IO Handle
- bindPort :: Int -> String -> IO Socket
- enumSocket :: Handle -> Int -> Socket -> Enumerator ByteString IO a
- pause :: Handle -> IO ()
- resume :: Handle -> IO ()
- cancel :: Handle -> IO ()
- register :: Manager -> IO () -> IO Handle
- initialize :: Int -> IO Manager
Run a Warp server
run :: Port -> Application -> IO ()
Run an Application on the given port. This calls runSettings with
defaultSettings.
runSettings :: Settings -> Application -> IO ()
Run a Warp server with the given settings.
runSettingsSocket :: Settings -> Socket -> Application -> IO ()
Same as runSettings, but uses a user-supplied socket instead of opening
one. This allows the user to provide, for example, Unix named socket, which
can be used when reverse HTTP proxying into your application.
Note that the settingsPort will still be passed to Applications via the
serverPort record.
Settings
data Settings
Various Warp server settings. This is purposely kept as an abstract data
type so that new settings can be added without breaking backwards
compatibility. In order to create a Settings value, use defaultSettings
and record syntax to modify individual records. For example:
defaultSettings { settingsTimeout = 20 }
The default settings for the Warp server. See the individual settings for the default value.
settingsPort :: Settings -> Int
Port to listen on. Default value: 3000
settingsHost :: Settings -> String
Host to bind to, or * for all. Default value: *
settingsOnException :: Settings -> SomeException -> IO ()
What to do with exceptions thrown by either the application or server. Default: ignore server-generated exceptions (see InvalidRequest) and print application-generated applications to stderr.
settingsTimeout :: Settings -> Int
Timeout value in seconds. Default value: 30
settingsIntercept :: Settings -> Request -> Maybe (Socket -> Iteratee ByteString IO ())
settingsManager :: Settings -> Maybe Manager
Use an existing timeout manager instead of spawning a new one. If used, settingsTimeout is ignored. Default is Nothing
Datatypes
data InvalidRequest
Internal
data Manager
A timeout manager
Call the inner function with a timeout manager.
parseRequest :: Port -> SockAddr -> Iteratee ByteString IO (Integer, Request)
registerKillThread :: Manager -> IO Handle
enumSocket :: Handle -> Int -> Socket -> Enumerator ByteString IO a
initialize :: Int -> IO Manager