on master help sign in
throwIO
c09d833Michael Snoyman
Network/Wai/Handler/Warp.hs+10−8
@@ -55,7 +55,7 @@ import Network.Socket
55 ( accept, SockAddr
55 ( accept, SockAddr
56 )
56 )
57import qualified Network.Socket.ByteString as Sock
57import 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)
59import Control.Concurrent (forkIO)
59import Control.Concurrent (forkIO)
60import Data.Maybe (fromMaybe)
60import Data.Maybe (fromMaybe)
61
61
@@ -170,7 +170,7 @@ parseRequest' :: Port
170 -> [ByteString]
170 -> [ByteString]
171 -> SockAddr
171 -> SockAddr
172 -> E.Iteratee S.ByteString IO (E.Enumeratee S.ByteString S.ByteString IO a, Request)
172 -> E.Iteratee S.ByteString IO (E.Enumeratee S.ByteString S.ByteString IO a, Request)
173−parseRequest' _ [] _ = E.throwError $ NotEnoughLines []
173+parseRequest' _ [] _ = throwError $ NotEnoughLines []
174parseRequest' port (firstLine:otherLines) remoteHost' = do
174parseRequest' port (firstLine:otherLines) remoteHost' = do
175 (method, rpath', gets, httpversion) <- parseFirst firstLine
175 (method, rpath', gets, httpversion) <- parseFirst firstLine
176 let rpath =
176 let rpath =
@@ -217,13 +217,13 @@ parseFirst s = do
217 (method, query, http') <-
217 (method, query, http') <-
218 case pieces of
218 case pieces of
219 [x, y, z] -> return (x, y, z)
219 [x, y, z] -> return (x, y, z)
220− _ -> E.throwError $ BadFirstLine $ B.unpack s
220+ _ -> throwError $ BadFirstLine $ B.unpack s
221 let (hfirst, hsecond) = B.splitAt 5 http'
221 let (hfirst, hsecond) = B.splitAt 5 http'
222 if (hfirst == "HTTP/")
222 if (hfirst == "HTTP/")
223 then
223 then
224 let (rpath, qstring) = B.break (== '?') query
224 let (rpath, qstring) = B.break (== '?') query
225 in return (method, rpath, qstring, hsecond)
225 in return (method, rpath, qstring, hsecond)
226− else E.throwError NonHttp
226+ else throwError NonHttp
227{-# INLINE parseFirst #-} -- FIXME is this inline necessary? the function is only called from one place and not exported
227{-# INLINE parseFirst #-} -- FIXME is this inline necessary? the function is only called from one place and not exported
228
228
229httpBuilder, spaceBuilder, newlineBuilder, transferEncodingBuilder
229httpBuilder, spaceBuilder, newlineBuilder, transferEncodingBuilder
@@ -341,7 +341,7 @@ enumSocket len socket (E.Continue k) = do
341#else
341#else
342 mbs <- liftIO $ timeout readTimeout $ Sock.recv socket len
342 mbs <- liftIO $ timeout readTimeout $ Sock.recv socket len
343 case mbs of
343 case mbs of
344− Nothing -> E.throwError SocketTimeout
344+ Nothing -> throwError SocketTimeout
345 Just bs -> go bs
345 Just bs -> go bs
346#endif
346#endif
347 where
347 where
@@ -360,7 +360,7 @@ takeUntilBlank :: Int
360 -> ([ByteString] -> [ByteString])
360 -> ([ByteString] -> [ByteString])
361 -> E.Iteratee S.ByteString IO [ByteString]
361 -> E.Iteratee S.ByteString IO [ByteString]
362takeUntilBlank count _
362takeUntilBlank count _
363− | count > maxHeaders = E.throwError TooManyHeaders
363+ | count > maxHeaders = throwError TooManyHeaders
364takeUntilBlank count front = do
364takeUntilBlank count front = do
365 l <- takeLineMax 0 id
365 l <- takeLineMax 0 id
366 if B.null l
366 if B.null l
@@ -373,7 +373,7 @@ takeLineMax :: Int
373takeLineMax len front = do
373takeLineMax len front = do
374 mbs <- EL.head
374 mbs <- EL.head
375 case mbs of
375 case mbs of
376− Nothing -> E.throwError IncompleteHeaders
376+ Nothing -> throwError IncompleteHeaders
377 Just bs -> do
377 Just bs -> do
378 let (x, y) = S.breakByte 10 bs
378 let (x, y) = S.breakByte 10 bs
379 x' = if S.length x > 0 && S.last x == 13
379 x' = if S.length x > 0 && S.last x == 13
@@ -382,8 +382,10 @@ takeLineMax len front = do
382 let len' = len + B.length x
382 let len' = len + B.length x
383 case () of
383 case () of
384 ()
384 ()
385− | len' > maxHeaderLength -> E.throwError OverLargeHeader
385+ | len' > maxHeaderLength -> throwError OverLargeHeader
386 | B.null y -> takeLineMax len' $ front . (:) x
386 | B.null y -> takeLineMax len' $ front . (:) x
387 | otherwise -> do
387 | otherwise -> do
388 E.yield () $ E.Chunks [B.drop 1 y]
388 E.yield () $ E.Chunks [B.drop 1 y]
389 return $ B.concat $ front [x']
389 return $ B.concat $ front [x']
390+
391+throwError = liftIO . throwIO