on master help sign in
new settingsOnOpen for access control.
commitfa9a7aa2b637a688e9d81dbda69464c3d5e8a8b5 authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 7 Feb 2014, 11:43 (13 years ago) parent81964b7
2 files changed+6−4
warp/Network/Wai/Handler/Warp/Run.hs+3−2 warp/Network/Wai/Handler/Warp/Settings.hs+3−2
warp/Network/Wai/Handler/Warp/Run.hs+3−2
@@ -185,10 +185,11 @@ runSettingsConnectionMaker set getConnMaker app = do
185185 handle (onE Nothing) .
186186
187187 -- Call the user-supplied code for connection open and close events
188− bracket_ onOpen onClose $
188+ bracket (onOpen addr) (const onClose) $ \goingon ->
189189
190190 -- Actually serve this connection.
191− serveConnection conn ii addr set app
191+ -- onnClose above ensures the termination of the connection.
192+ when goingon $ serveConnection conn ii addr set app
192193 where
193194 -- FIXME: only IOEception is caught. What about other exceptions?
194195 getConnLoop = getConnMaker `E.catch` \(e :: IOException) -> do
warp/Network/Wai/Handler/Warp/Settings.hs+3−2
@@ -9,6 +9,7 @@ import Data.Conduit
99import Data.Conduit.Network (HostPreference (HostIPv4))
1010import GHC.IO.Exception (IOErrorType(..))
1111import qualified Network.HTTP.Types as H
12+import Network.Socket (SockAddr)
1213import Network.Wai
1314import Network.Wai.Handler.Warp.Timeout
1415import Network.Wai.Handler.Warp.Types
@@ -31,7 +32,7 @@ data Settings = Settings
3132 -- Default: 500, text/plain, \"Something went wrong\"
3233 --
3334 -- Since 2.0.3
34− , settingsOnOpen :: IO () -- ^ What to do when a connection is open. Default: do nothing.
35+ , settingsOnOpen :: SockAddr -> IO Bool -- ^ What to do when a connection is open. When 'False' is returned, the connection is closed immediately. Otherwise, the connection is going on. Default: always returns 'True'.
3536 , settingsOnClose :: IO () -- ^ What to do when a connection is close. Default: do nothing.
3637 , settingsTimeout :: Int -- ^ Timeout value in seconds. Default value: 30
3738 , settingsIntercept :: Request -> Maybe (Source IO S.ByteString -> Connection -> IO ())
@@ -63,7 +64,7 @@ defaultSettings = Settings
6364 , settingsHost = HostIPv4
6465 , settingsOnException = defaultExceptionHandler
6566 , settingsOnExceptionResponse = defaultExceptionResponse
66− , settingsOnOpen = return ()
67+ , settingsOnOpen = const $ return True
6768 , settingsOnClose = return ()
6869 , settingsTimeout = 30
6970 , settingsIntercept = const Nothing