@@ -1,6 +1,7 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE OverloadedStrings #-}
33{-# LANGUAGE ScopedTypeVariables #-}
4+{-# LANGUAGE TupleSections #-}
45{-# OPTIONS_GHC -fno-warn-deprecations #-}
56
67module Network.Wai.Handler.Warp.Run where
@@ -124,10 +125,18 @@ runSettingsConnection set getConn app = runSettingsConnectionMaker set getConnMa
124125 (conn, sa) <- getConn
125126 return (return conn, sa)
126127
128+runSettingsConnectionMaker :: Settings -> IO (IO Connection, SockAddr) -> Application -> IO ()
129+runSettingsConnectionMaker x y =
130+ runSettingsConnectionMakerSecure x (go y)
131+ where
132+ go = fmap (\(a, b) -> (fmap (, False) a, b))
133+
127134-- | Allows you to provide a function which will return a function
128135-- which will return 'Connection'.
129−runSettingsConnectionMaker :: Settings -> IO (IO Connection, SockAddr) -> Application -> IO ()
130−runSettingsConnectionMaker set getConnMaker app = do
136+--
137+-- Since 2.1.4
138+runSettingsConnectionMakerSecure :: Settings -> IO (IO (Connection, Bool), SockAddr) -> Application -> IO ()
139+runSettingsConnectionMakerSecure set getConnMaker app = do
131140 settingsBeforeMainLoop set
132141
133142 -- Note that there is a thorough discussion of the exception safety of the
@@ -175,7 +184,7 @@ runSettingsConnectionMaker set getConnMaker app = do
175184 -- We grab the connection before registering timeouts since the
176185 -- timeouts will be useless during connection creation, due to the
177186 -- fact that async exceptions are still masked.
178− bracket mkConn connClose $ \conn' ->
187+ bracket mkConn (connClose . fst) $ \(conn', isSecure') ->
179188
180189 -- We need to register a timeout handler for this thread, and
181190 -- cancel that handler as soon as we exit.
@@ -195,7 +204,7 @@ runSettingsConnectionMaker set getConnMaker app = do
195204
196205 -- Actually serve this connection.
197206 -- onnClose above ensures the termination of the connection.
198− when goingon $ serveConnection conn ii addr set app
207+ when goingon $ serveConnection conn ii addr isSecure' set app
199208 where
200209 -- FIXME: only IOEception is caught. What about other exceptions?
201210 getConnLoop = getConnMaker `E.catch` \(e :: IOException) -> do
@@ -222,10 +231,11 @@ runSettingsConnectionMaker set getConnMaker app = do
222231serveConnection :: Connection
223232 -> InternalInfo
224233 -> SockAddr
234+ -> Bool -- ^ is secure?
225235 -> Settings
226236 -> Application
227237 -> IO ()
228−serveConnection conn ii addr settings app = do
238+serveConnection conn ii addr isSecure' settings app = do
229239 istatus <- newIORef False
230240 recvSendLoop istatus (connSource conn th istatus) `E.catch` \e -> do
231241 sendErrorResponse istatus e
@@ -244,7 +254,8 @@ serveConnection conn ii addr settings app = do
244254 errorResponse e = settingsOnExceptionResponse settings e
245255
246256 recvSendLoop istatus fromClient = do
247− (req, idxhdr, getSource, leftover') <- recvRequest settings conn ii addr fromClient
257+ (req', idxhdr, getSource, leftover') <- recvRequest settings conn ii addr fromClient
258+ let req = req' { isSecure = isSecure' }
248259 intercept' <- settingsIntercept settings req
249260 case intercept' of
250261 Nothing -> do