@@ -23,8 +23,15 @@
2323-- corner case is partial request body consumption; in that case, Warp's
2424-- timeout handling is still in effect, and the timeout will not be triggered
2525-- again. Therefore, it is recommended that once you start consuming the
26−-- request body, you consume the entire body promptly. For more information,
27−-- see <https://github.com/yesodweb/wai/issues/351>.
26+-- request body, you either:
27+--
28+-- * consume the entire body promptly
29+--
30+-- * call the 'pauseTimeout' function
31+--
32+-- For more information, see <https://github.com/yesodweb/wai/issues/351>.
33+--
34+--
2835module Network.Wai.Handler.Warp (
2936 -- * Run a Warp server
3037 run
@@ -81,6 +88,8 @@ module Network.Wai.Handler.Warp (
8188 , Port
8289 , InvalidRequest (..)
8390 , ConnSendFileOverride (..)
91+ -- * Per-request utilities
92+ , pauseTimeout
8493 -- * Connection
8594 , Connection (..)
8695 , socketConnection
@@ -113,10 +122,12 @@ import Network.Wai.Handler.Warp.Settings
113122import Network.Wai.Handler.Warp.Timeout
114123import Network.Wai.Handler.Warp.Types
115124import Control.Exception (SomeException)
116−import Network.Wai (Request, Response)
125+import Network.Wai (Request, Response, vault)
117126import Network.Socket (SockAddr)
118127import Data.Streaming.Network (HostPreference)
119128import Data.ByteString (ByteString)
129+import qualified Data.Vault.Lazy as Vault
130+import Data.Maybe (fromMaybe)
120131
121132-- | Port to listen on. Default value: 3000
122133--
@@ -292,3 +303,12 @@ setProxyProtocolRequired y = y { settingsProxyProtocol = ProxyProtocolRequired }
292303-- Since 3.0.5
293304setProxyProtocolOptional :: Settings -> Settings
294305setProxyProtocolOptional y = y { settingsProxyProtocol = ProxyProtocolOptional }
306+
307+-- | Explicitly pause the slowloris timeout.
308+--
309+-- This is useful for cases where you partially consume a request body. For
310+-- more information, see <https://github.com/yesodweb/wai/issues/351>
311+--
312+-- Since 3.0.10
313+pauseTimeout :: Request -> IO ()
314+pauseTimeout = fromMaybe (return ()) . Vault.lookup pauseTimeoutKey . vault