@@ -26,18 +26,16 @@ import qualified Data.ByteString.Char8 as B
26import Network
26import Network
27 ( listenOn, accept, sClose, PortID(PortNumber), Socket
27 ( listenOn, accept, sClose, PortID(PortNumber), Socket
28 , withSocketsDo)
28 , withSocketsDo)
29−import Control.Exception (bracket, finally, Exception)
29+import Control.Exception (bracket, finally, Exception, throwIO)
30import System.IO (Handle, hClose)
30import System.IO (Handle, hClose)
31import Control.Concurrent (forkIO)
31import Control.Concurrent (forkIO)
32import Control.Monad (unless)
32import Control.Monad (unless)
33import Data.Maybe (isJust, fromJust, fromMaybe)
33import Data.Maybe (isJust, fromJust, fromMaybe)
35−import Control.Failure
36import Data.Typeable (Typeable)
35import Data.Typeable (Typeable)
38import qualified Web.Encodings.StringLike as SL
37import qualified Web.Encodings.StringLike as SL
41import Network.Socket.SendFile
39import Network.Socket.SendFile
42import Control.Arrow (first)
40import Control.Arrow (first)
@@ -103,7 +101,7 @@ parseRequest :: Port
103parseRequest port lines' handle remoteHost' = do
101parseRequest port lines' handle remoteHost' = do
104 case lines' of
102 case lines' of
105 (_:_:_) -> return ()
103 (_:_:_) -> return ()
106− _ -> failure $ NotEnoughLines $ map B.unpack lines'
104+ _ -> throwIO $ NotEnoughLines $ map B.unpack lines'
107 (method', rpath', gets, httpversion) <- parseFirst $ head lines'
105 (method', rpath', gets, httpversion) <- parseFirst $ head lines'
108 let method = methodFromBS method'
106 let method = methodFromBS method'
109 let rpath = '/' : case B.unpack rpath' of
107 let rpath = '/' : case B.unpack rpath' of
@@ -112,12 +110,14 @@ parseRequest port lines' handle remoteHost' = do
112 let heads = map (first requestHeaderFromBS . parseHeaderNoAttr)
110 let heads = map (first requestHeaderFromBS . parseHeaderNoAttr)
113 $ tail lines'
111 $ tail lines'
114 let host' = lookup Host heads
112 let host' = lookup Host heads
115− unless (isJust host') $ failure HostNotIncluded
113+ unless (isJust host') $ throwIO HostNotIncluded
116 let host = fromJust host'
114 let host = fromJust host'
117 let len = fromMaybe 0 $ do
115 let len = fromMaybe 0 $ do
118 bs <- lookup ReqContentLength heads
116 bs <- lookup ReqContentLength heads
119 let str = B.unpack bs
117 let str = B.unpack bs
120− Safe.readMay str
118+ case reads str of
121 let (serverName', _) = B.break (== ':') host
121 let (serverName', _) = B.break (== ':') host
122 return $ Request
122 return $ Request
123 { requestMethod = method
123 { requestMethod = method
@@ -140,9 +140,9 @@ parseFirst s = do
140 (method, query, http') <-
140 (method, query, http') <-
141 case pieces of
141 case pieces of
142 [x, y, z] -> return (x, y, z)
142 [x, y, z] -> return (x, y, z)
143− _ -> failure $ BadFirstLine $ B.unpack s
143+ _ -> throwIO $ BadFirstLine $ B.unpack s
144 let (hfirst, hsecond) = B.splitAt 5 http'
144 let (hfirst, hsecond) = B.splitAt 5 http'
145− unless (hfirst == B.pack "HTTP/") $ failure NonHttp
145+ unless (hfirst == B.pack "HTTP/") $ throwIO NonHttp
146 let (rpath, qstring) = B.break (== '?') query
146 let (rpath, qstring) = B.break (== '?') query
147 return (method, rpath, qstring, httpVersionFromBS hsecond)
147 return (method, rpath, qstring, httpVersionFromBS hsecond)