on master help sign in
doc update.
1d71cc5Kazu Yamamoto
warp/Network/Wai/Handler/Warp.hs+3−5
@@ -20,6 +20,8 @@ module Network.Wai.Handler.Warp (
20 run
20 run
21 , runSettings
21 , runSettings
22 , runSettingsSocket
22 , runSettingsSocket
23+ , runSettingsConnection
24+ , runSettingsConnectionMaker
23 -- * Settings
25 -- * Settings
24 , Settings
26 , Settings
25 , defaultSettings
27 , defaultSettings
@@ -36,12 +38,8 @@ module Network.Wai.Handler.Warp (
36 , settingsServerName
38 , settingsServerName
37 -- ** Data types
39 -- ** Data types
38 , HostPreference (..)
40 , HostPreference (..)
39− -- * Connection
40− , Connection (..)
41− , runSettingsConnection
42− , runSettingsConnectionMaker
43− -- * Datatypes
44 , Port
41 , Port
42+ , Connection (..)
45 , InvalidRequest (..)
43 , InvalidRequest (..)
46 -- * Internal
44 -- * Internal
47 -- ** Time out manager
45 -- ** Time out manager
warp/Network/Wai/Handler/Warp/Run.hs+9−7
@@ -80,7 +80,7 @@ allowInterrupt = unblock $ return ()
80run :: Port -> Application -> IO ()
80run :: Port -> Application -> IO ()
81run p = runSettings defaultSettings { settingsPort = p }
81run p = runSettings defaultSettings { settingsPort = p }
82
82
83−-- | Run a Warp server with the given settings.
83+-- | Run an 'Applicatoin' with the given 'Settings'.
84runSettings :: Settings -> Application -> IO ()
84runSettings :: Settings -> Application -> IO ()
85#if WINDOWS
85#if WINDOWS
86runSettings set app = withSocketsDo $ do
86runSettings set app = withSocketsDo $ do
@@ -119,6 +119,12 @@ runSettingsSocket set socket app =
119 conn <- socketConnection s
119 conn <- socketConnection s
120 return (conn, sa)
120 return (conn, sa)
121
121
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
122runSettingsConnection :: Settings -> IO (Connection, SockAddr) -> Application -> IO ()
128runSettingsConnection :: Settings -> IO (Connection, SockAddr) -> Application -> IO ()
123runSettingsConnection set getConn app = runSettingsConnectionMaker set getConnMaker app
129runSettingsConnection set getConn app = runSettingsConnectionMaker set getConnMaker app
124 where
130 where
@@ -126,12 +132,8 @@ runSettingsConnection set getConn app = runSettingsConnectionMaker set getConnMa
126 (conn, sa) <- getConn
132 (conn, sa) <- getConn
127 return (return conn, sa)
133 return (return conn, sa)
128
134
129−-- | Allows you to provide a function which will return a @Connection@. In
135+-- | Allows you to provide a function which will return a function
130−-- cases where creating the @Connection@ can be expensive, this allows the
136+-- which will return 'Connection'.
131−-- expensive computations to be performed in a separate thread instead of the
132−-- main server loop.
133−--
134−-- Since 1.3.5
135runSettingsConnectionMaker :: Settings -> IO (IO Connection, SockAddr) -> Application -> IO ()
137runSettingsConnectionMaker :: Settings -> IO (IO Connection, SockAddr) -> Application -> IO ()
136runSettingsConnectionMaker set getConnMaker app = do
138runSettingsConnectionMaker set getConnMaker app = do
137#if SENDFILEFD
139#if SENDFILEFD
warp/Network/Wai/Handler/Warp/Timeout.hs+21−2
@@ -2,6 +2,25 @@
2{-# LANGUAGE BangPatterns #-}
2{-# LANGUAGE BangPatterns #-}
3{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE DeriveDataTypeable #-}
4{-# LANGUAGE UnboxedTuples, MagicHash #-}
4{-# 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+
5module Network.Wai.Handler.Warp.Timeout (
24module Network.Wai.Handler.Warp.Timeout (
6 -- * Types
25 -- * Types
7 Manager
26 Manager
@@ -158,8 +177,8 @@ cancel (Handle _ iactive) = I.writeIORef iactive Canceled
158pause :: Handle -> IO ()
177pause :: Handle -> IO ()
159pause (Handle _ iactive) = I.writeIORef iactive Paused
178pause (Handle _ iactive) = I.writeIORef iactive Paused
160
179
161−-- | Setting the state to active.
180+-- | Setting the paused state to active.
162−-- This is an alias to 'ticle'.
181+-- This is an alias to 'tickle'.
163resume :: Handle -> IO ()
182resume :: Handle -> IO ()
164resume = tickle
183resume = tickle
165
184
warp/Network/Wai/Handler/Warp/Types.hs+3−18
@@ -38,6 +38,7 @@ hServer = "Server"
38
38
39----------------------------------------------------------------
39----------------------------------------------------------------
40
40
41+-- | Error types for bad 'Request'.
41data InvalidRequest =
42data InvalidRequest =
42 NotEnoughLines [String]
43 NotEnoughLines [String]
43 | BadFirstLine String
44 | BadFirstLine String
@@ -51,27 +52,11 @@ instance Exception InvalidRequest
51
52
52----------------------------------------------------------------
53----------------------------------------------------------------
53
54
54−-- |
55+-- | Data type to manipulate IO actions for connections.
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.
71data Connection = Connection
56data Connection = Connection
72 { connSendMany :: [ByteString] -> IO ()
57 { connSendMany :: [ByteString] -> IO ()
73 , connSendAll :: ByteString -> IO ()
58 , 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
75 , connClose :: IO ()
60 , connClose :: IO ()
76 , connRecv :: IO ByteString
61 , connRecv :: IO ByteString
77 }
62 }