on master help sign in
Revert "settingsPauseForApp"

This reverts commit d2b6c66abef939bb1396d576e7541b711a6db67b. Conflicts: warp/Network/Wai/Handler/Warp.hs

commit3fe287767cb2252776f20b8a6bc2806c54971f7c authorMichael Snoyman <michael@snoyman.com> dateThu 6 Oct 2011, 09:45 (15 years ago) parent2ba7c5f
1 file changed+9−22
warp/Network/Wai/Handler/Warp.hs+9−22
warp/Network/Wai/Handler/Warp.hs+9−22
@@ -34,7 +34,6 @@ module Network.Wai.Handler.Warp
3434 , settingsHost
3535 , settingsOnException
3636 , settingsTimeout
37− , settingsPauseForApp
3837 , settingsIntercept
3938 -- * Datatypes
4039 , Port
@@ -103,7 +102,7 @@ import qualified Timeout as T
103102import Timeout (Manager, registerKillThread, pause, resume)
104103import Data.Word (Word8)
105104import Data.List (foldl')
106−import Control.Monad (forever, when)
105+import Control.Monad (forever)
107106import qualified Network.HTTP.Types as H
108107import qualified Data.CaseInsensitive as CI
109108import System.IO (hPutStrLn, stderr)
@@ -208,7 +207,7 @@ serveConnection settings th onException port app conn remoteHost' = do
208207 liftIO $ T.pause th
209208 res <- E.joinI $ EB.isolate len $$ app env
210209 liftIO $ T.resume th
211− keepAlive <- liftIO $ sendResponse' settings th env conn res
210+ keepAlive <- liftIO $ sendResponse th env conn res
212211 if keepAlive then serveConnection' else return ()
213212 Just intercept -> do
214213 liftIO $ T.pause th
@@ -350,14 +349,9 @@ hasBody :: H.Status -> Request -> Bool
350349hasBody s req = s /= (H.Status 204 "") && s /= H.status304 &&
351350 H.statusCode s >= 200 && requestMethod req /= "HEAD"
352351
353−-- Only present for backwards-compatibility
354352sendResponse :: T.Handle
355353 -> Request -> Socket -> Response -> IO Bool
356−sendResponse = sendResponse' defaultSettings
357−
358−sendResponse' :: Settings -> T.Handle
359− -> Request -> Socket -> Response -> IO Bool
360−sendResponse' _ th req socket (ResponseFile s hs fp mpart) = do
354+sendResponse th req socket (ResponseFile s hs fp mpart) = do
361355 (hs', cl) <-
362356 case (readInt `fmap` lookup "content-length" hs, mpart) of
363357 (Just cl, _) -> return (hs, cl)
@@ -383,7 +377,7 @@ sendResponse' _ th req socket (ResponseFile s hs fp mpart) = do
383377 T.tickle th
384378 return isPersist
385379 else return isPersist
386−sendResponse' _ th req socket (ResponseBuilder s hs b)
380+sendResponse th req socket (ResponseBuilder s hs b)
387381 | hasBody s req = do
388382 toByteStringIO (\bs -> do
389383 Sock.sendAll socket bs
@@ -407,7 +401,7 @@ sendResponse' _ th req socket (ResponseBuilder s hs b)
407401 isChunked' = isChunked (httpVersion req) && not hasLength
408402 isPersist = checkPersist req
409403 isKeepAlive = isPersist && (isChunked' || hasLength)
410−sendResponse' settings th req socket (ResponseEnumerator res) =
404+sendResponse th req socket (ResponseEnumerator res) =
411405 res go
412406 where
413407 -- FIXME perhaps alloca a buffer per thread and reuse that in all functiosn below. Should lessen greatly the GC burden (I hope)
@@ -419,9 +413,8 @@ sendResponse' settings th req socket (ResponseEnumerator res) =
419413 go s hs = chunk'
420414 $ E.enumList 1 [headers (httpVersion req) s hs isChunked']
421415 $$ E.joinI $ builderToByteString -- FIXME unsafeBuilderToByteString
422− $$ (iterSocket pauseForApp th socket >> return isKeepAlive)
416+ $$ (iterSocket th socket >> return isKeepAlive)
423417 where
424− pauseForApp = settingsPauseForApp settings
425418 hasLength = lookup "content-length" hs /= Nothing
426419 isChunked' = isChunked (httpVersion req) && not hasLength
427420 isPersist = checkPersist req
@@ -460,26 +453,22 @@ enumSocket th len socket =
460453------ The functions below are not warp-specific and could be split out into a
461454--separate package.
462455
463−iterSocket :: Bool -- ^ should this be paused? see 'settingsPauseForApp'
464− -> T.Handle
456+iterSocket :: T.Handle
465457 -> Socket
466458 -> E.Iteratee B.ByteString IO ()
467−iterSocket pauseForApp th sock =
459+iterSocket th sock =
468460 E.continue step
469461 where
470462 -- We pause timeouts before passing control back to user code. This ensures
471463 -- that a timeout will only ever be executed when Warp is in control. We
472464 -- also make sure to resume the timeout after the completion of user code
473465 -- so that we can kill idle connections.
474− --
475− -- If settingsPauseForApp is 'True', then the timeout will
476− -- not be paused during 'ResponseEnumerator' responses.
477466 step E.EOF = liftIO (T.resume th) >> E.yield () E.EOF
478467 step (E.Chunks []) = E.continue step
479468 step (E.Chunks xs) = do
480469 liftIO $ T.resume th
481470 liftIO $ Sock.sendMany sock xs
482− when pauseForApp $ liftIO $ T.pause th
471+ liftIO $ T.pause th
483472 E.continue step
484473
485474-- | Various Warp server settings. This is purposely kept as an abstract data
@@ -493,7 +482,6 @@ data Settings = Settings
493482 , settingsHost :: String -- ^ Host to bind to, or * for all. Default value: *
494483 , settingsOnException :: 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.
495484 , settingsTimeout :: Int -- ^ Timeout value in seconds. Default value: 30
496− , settingsPauseForApp :: Bool -- ^ If 'True', timeout will be paused while executing the application, 'False' otherwise. Default is 'True'. 'False' is useful for cases such as an untrusted CGI application. Note that this /only/ affects execution of 'ResponseEnumerator' responses.
497485 , settingsIntercept :: Request -> Maybe (Socket -> E.Iteratee S.ByteString IO ())
498486 }
499487
@@ -511,7 +499,6 @@ defaultSettings = Settings
511499 then hPutStrLn stderr $ show e
512500 else return ()
513501 , settingsTimeout = 30
514− , settingsPauseForApp = True
515502 , settingsIntercept = const Nothing
516503 }
517504 where