on master help sign in
throwIO
commitc09d83377b68e8ae2afa368ce6c5d77f57b53214 authorMichael Snoyman <michael@snoyman.com> dateThu 3 Feb 2011, 13:28 (16 years ago) parent8e4a1cb
1 file changed+10−8
Network/Wai/Handler/Warp.hs+10−8
Network/Wai/Handler/Warp.hs+10−8
@@ -55,7 +55,7 @@ import Network.Socket
5555 ( accept, SockAddr
5656 )
5757import qualified Network.Socket.ByteString as Sock
58−import Control.Exception (bracket, finally, Exception, SomeException, catch)
58+import Control.Exception (bracket, finally, Exception, SomeException, catch, throwIO)
5959import Control.Concurrent (forkIO)
6060import Data.Maybe (fromMaybe)
6161
@@ -170,7 +170,7 @@ parseRequest' :: Port
170170 -> [ByteString]
171171 -> SockAddr
172172 -> E.Iteratee S.ByteString IO (E.Enumeratee S.ByteString S.ByteString IO a, Request)
173−parseRequest' _ [] _ = E.throwError $ NotEnoughLines []
173+parseRequest' _ [] _ = throwError $ NotEnoughLines []
174174parseRequest' port (firstLine:otherLines) remoteHost' = do
175175 (method, rpath', gets, httpversion) <- parseFirst firstLine
176176 let rpath =
@@ -217,13 +217,13 @@ parseFirst s = do
217217 (method, query, http') <-
218218 case pieces of
219219 [x, y, z] -> return (x, y, z)
220− _ -> E.throwError $ BadFirstLine $ B.unpack s
220+ _ -> throwError $ BadFirstLine $ B.unpack s
221221 let (hfirst, hsecond) = B.splitAt 5 http'
222222 if (hfirst == "HTTP/")
223223 then
224224 let (rpath, qstring) = B.break (== '?') query
225225 in return (method, rpath, qstring, hsecond)
226− else E.throwError NonHttp
226+ else throwError NonHttp
227227{-# INLINE parseFirst #-} -- FIXME is this inline necessary? the function is only called from one place and not exported
228228
229229httpBuilder, spaceBuilder, newlineBuilder, transferEncodingBuilder
@@ -341,7 +341,7 @@ enumSocket len socket (E.Continue k) = do
341341#else
342342 mbs <- liftIO $ timeout readTimeout $ Sock.recv socket len
343343 case mbs of
344− Nothing -> E.throwError SocketTimeout
344+ Nothing -> throwError SocketTimeout
345345 Just bs -> go bs
346346#endif
347347 where
@@ -360,7 +360,7 @@ takeUntilBlank :: Int
360360 -> ([ByteString] -> [ByteString])
361361 -> E.Iteratee S.ByteString IO [ByteString]
362362takeUntilBlank count _
363− | count > maxHeaders = E.throwError TooManyHeaders
363+ | count > maxHeaders = throwError TooManyHeaders
364364takeUntilBlank count front = do
365365 l <- takeLineMax 0 id
366366 if B.null l
@@ -373,7 +373,7 @@ takeLineMax :: Int
373373takeLineMax len front = do
374374 mbs <- EL.head
375375 case mbs of
376− Nothing -> E.throwError IncompleteHeaders
376+ Nothing -> throwError IncompleteHeaders
377377 Just bs -> do
378378 let (x, y) = S.breakByte 10 bs
379379 x' = if S.length x > 0 && S.last x == 13
@@ -382,8 +382,10 @@ takeLineMax len front = do
382382 let len' = len + B.length x
383383 case () of
384384 ()
385− | len' > maxHeaderLength -> E.throwError OverLargeHeader
385+ | len' > maxHeaderLength -> throwError OverLargeHeader
386386 | B.null y -> takeLineMax len' $ front . (:) x
387387 | otherwise -> do
388388 E.yield () $ E.Chunks [B.drop 1 y]
389389 return $ B.concat $ front [x']
390+
391+throwError = liftIO . throwIO