on master help sign in
doc update.
commit1d71cc59ef7528ab80d95810863f206a00cfacba authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 11 Oct 2013, 14:02 (13 years ago) parent953efb2
4 files changed+36−32
warp/Network/Wai/Handler/Warp.hs+3−5 warp/Network/Wai/Handler/Warp/Run.hs+9−7 warp/Network/Wai/Handler/Warp/Timeout.hs+21−2 warp/Network/Wai/Handler/Warp/Types.hs+3−18
warp/Network/Wai/Handler/Warp.hs+3−5
@@ -20,6 +20,8 @@ module Network.Wai.Handler.Warp (
2020 run
2121 , runSettings
2222 , runSettingsSocket
23+ , runSettingsConnection
24+ , runSettingsConnectionMaker
2325 -- * Settings
2426 , Settings
2527 , defaultSettings
@@ -36,12 +38,8 @@ module Network.Wai.Handler.Warp (
3638 , settingsServerName
3739 -- ** Data types
3840 , HostPreference (..)
39− -- * Connection
40− , Connection (..)
41− , runSettingsConnection
42− , runSettingsConnectionMaker
43− -- * Datatypes
4441 , Port
42+ , Connection (..)
4543 , InvalidRequest (..)
4644 -- * Internal
4745 -- ** Time out manager
warp/Network/Wai/Handler/Warp/Run.hs+9−7
@@ -80,7 +80,7 @@ allowInterrupt = unblock $ return ()
8080run :: Port -> Application -> IO ()
8181run p = runSettings defaultSettings { settingsPort = p }
8282
83−-- | Run a Warp server with the given settings.
83+-- | Run an 'Applicatoin' with the given 'Settings'.
8484runSettings :: Settings -> Application -> IO ()
8585#if WINDOWS
8686runSettings set app = withSocketsDo $ do
@@ -119,6 +119,12 @@ runSettingsSocket set socket app =
119119 conn <- socketConnection s
120120 return (conn, sa)
121121
122+-- | Allows you to provide a function which will return a 'Connection'. In
123+-- cases where creating the @Connection@ can be expensive, this allows the
124+-- expensive computations to be performed in a separate thread instead of the
125+-- main server loop.
126+--
127+-- Since 1.3.5
122128runSettingsConnection :: Settings -> IO (Connection, SockAddr) -> Application -> IO ()
123129runSettingsConnection set getConn app = runSettingsConnectionMaker set getConnMaker app
124130 where
@@ -126,12 +132,8 @@ runSettingsConnection set getConn app = runSettingsConnectionMaker set getConnMa
126132 (conn, sa) <- getConn
127133 return (return conn, sa)
128134
129−-- | Allows you to provide a function which will return a @Connection@. In
130−-- cases where creating the @Connection@ can be expensive, this allows the
131−-- expensive computations to be performed in a separate thread instead of the
132−-- main server loop.
133−--
134−-- Since 1.3.5
135+-- | Allows you to provide a function which will return a function
136+-- which will return 'Connection'.
135137runSettingsConnectionMaker :: Settings -> IO (IO Connection, SockAddr) -> Application -> IO ()
136138runSettingsConnectionMaker set getConnMaker app = do
137139#if SENDFILEFD
warp/Network/Wai/Handler/Warp/Timeout.hs+21−2
@@ -2,6 +2,25 @@
22{-# LANGUAGE BangPatterns #-}
33{-# LANGUAGE DeriveDataTypeable #-}
44{-# LANGUAGE UnboxedTuples, MagicHash #-}
5+
6+-- |
7+--
8+-- In order to provide slowloris protection, Warp provides timeout handlers. We
9+-- follow these rules:
10+--
11+-- * A timeout is created when a connection is opened.
12+--
13+-- * When all request headers are read, the timeout is tickled.
14+--
15+-- * Every time at least 2048 bytes of the request body are read, the timeout
16+-- is tickled.
17+--
18+-- * The timeout is paused while executing user code. This will apply to both
19+-- the application itself, and a ResponseSource response. The timeout is
20+-- resumed as soon as we return from user code.
21+--
22+-- * Every time data is successfully sent to the client, the timeout is tickled.
23+
524module Network.Wai.Handler.Warp.Timeout (
625 -- * Types
726 Manager
@@ -158,8 +177,8 @@ cancel (Handle _ iactive) = I.writeIORef iactive Canceled
158177pause :: Handle -> IO ()
159178pause (Handle _ iactive) = I.writeIORef iactive Paused
160179
161−-- | Setting the state to active.
162−-- This is an alias to 'ticle'.
180+-- | Setting the paused state to active.
181+-- This is an alias to 'tickle'.
163182resume :: Handle -> IO ()
164183resume = tickle
165184
warp/Network/Wai/Handler/Warp/Types.hs+3−18
@@ -38,6 +38,7 @@ hServer = "Server"
3838
3939----------------------------------------------------------------
4040
41+-- | Error types for bad 'Request'.
4142data InvalidRequest =
4243 NotEnoughLines [String]
4344 | BadFirstLine String
@@ -51,27 +52,11 @@ instance Exception InvalidRequest
5152
5253----------------------------------------------------------------
5354
54−-- |
55−--
56−-- In order to provide slowloris protection, Warp provides timeout handlers. We
57−-- follow these rules:
58−--
59−-- * A timeout is created when a connection is opened.
60−--
61−-- * When all request headers are read, the timeout is tickled.
62−--
63−-- * Every time at least 2048 bytes of the request body are read, the timeout
64−-- is tickled.
65−--
66−-- * The timeout is paused while executing user code. This will apply to both
67−-- the application itself, and a ResponseSource response. The timeout is
68−-- resumed as soon as we return from user code.
69−--
70−-- * Every time data is successfully sent to the client, the timeout is tickled.
55+-- | Data type to manipulate IO actions for connections.
7156data Connection = Connection
7257 { connSendMany :: [ByteString] -> IO ()
7358 , connSendAll :: ByteString -> IO ()
74− , connSendFile :: FilePath -> Integer -> Integer -> IO () -> [ByteString] -> Cleaner -> IO () -- ^ offset, length
59+ , connSendFile :: FilePath -> Integer -> Integer -> IO () -> [ByteString] -> Cleaner -> IO () -- ^ filepath, offset, length, hook action, HTTP headers, fd clear
7560 , connClose :: IO ()
7661 , connRecv :: IO ByteString
7762 }