Safe Haskell | Safe-Infered |
---|
A fast, light-weight HTTP server handler for WAI.
- run :: Port -> Application -> IO ()
- runSettings :: Settings -> Application -> IO ()
- runSettingsSocket :: Settings -> Socket -> Application -> IO ()
- data Settings
- defaultSettings :: Settings
- settingsPort :: Settings -> Int
- settingsHost :: Settings -> HostPreference
- settingsOnException :: Settings -> SomeException -> IO ()
- settingsTimeout :: Settings -> Int
- settingsIntercept :: Settings -> Request -> Maybe (Source (ResourceT IO) ByteString -> Connection -> ResourceT IO ())
- settingsManager :: Settings -> Maybe Manager
- data HostPreference = HostIPv4
- data Connection = Connection {
- connSendMany :: [ByteString] -> IO ()
- connSendAll :: ByteString -> IO ()
- connSendFile :: FilePath -> Integer -> Integer -> IO () -> IO ()
- connClose :: IO ()
- connRecv :: IO ByteString
- runSettingsConnection :: Settings -> IO (Connection, SockAddr) -> Application -> IO ()
- type Port = Int
- data InvalidRequest
- data Manager
- withManager :: Int -> (Manager -> IO a) -> IO a
- parseRequest :: Connection -> Port -> SockAddr -> Source (ResourceT IO) ByteString -> ResourceT IO (Request, IsolatedBSSource)
- sendResponse :: Handle -> Request -> Connection -> Response -> ResourceT IO Bool
- registerKillThread :: Manager -> IO Handle
- cancel, resume, pause :: Handle -> IO ()
- register :: Manager -> IO () -> IO Handle
- initialize :: Int -> IO Manager
Run a Warp server
run :: Port -> Application -> IO ()Source
Run an Application
on the given port. This calls runSettings
with
defaultSettings
.
runSettings :: Settings -> Application -> IO ()Source
Run a Warp server with the given settings.
runSettingsSocket :: Settings -> Socket -> Application -> IO ()Source
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 Application
s via the
serverPort
record.
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 }
defaultSettings :: SettingsSource
The default settings for the Warp server. See the individual settings for the default value.
settingsPort :: Settings -> IntSource
Port to listen on. Default value: 3000
settingsHost :: Settings -> HostPreferenceSource
Default value: HostIPv4
settingsOnException :: Settings -> SomeException -> IO ()Source
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 -> IntSource
Timeout value in seconds. Default value: 30
settingsIntercept :: Settings -> Request -> Maybe (Source (ResourceT IO) ByteString -> Connection -> ResourceT IO ())Source
settingsManager :: Settings -> Maybe ManagerSource
Use an existing timeout manager instead of spawning a new one. If used, settingsTimeout
is ignored. Default is Nothing
Data types
data HostPreference
Which host to bind.
Note: The IsString
instance recognizes the following special values:
-
*
meansHostAny
-
*4
meansHostIPv4
-
*6
meansHostIPv6
Connection
data Connection Source
In order to provide slowloris protection, Warp provides timeout handlers. We follow these rules:
- A timeout is created when a connection is opened.
- When all request headers are read, the timeout is tickled.
- Every time at least 2048 bytes of the request body are read, the timeout is tickled.
- The timeout is paused while executing user code. This will apply to both the application itself, and a ResponseSource response. The timeout is resumed as soon as we return from user code.
- Every time data is successfully sent to the client, the timeout is tickled.
Connection | |
|
runSettingsConnection :: Settings -> IO (Connection, SockAddr) -> Application -> IO ()Source
Datatypes
data InvalidRequest Source
Internal
Call the inner function with a timeout manager.
parseRequest :: Connection -> Port -> SockAddr -> Source (ResourceT IO) ByteString -> ResourceT IO (Request, IsolatedBSSource)Source
sendResponse :: Handle -> Request -> Connection -> Response -> ResourceT IO BoolSource
registerKillThread :: Manager -> IO HandleSource
initialize :: Int -> IO ManagerSource