@@ -209,7 +209,7 @@ serveConnection settings th onException port app conn remoteHost' = do
209 fromClient = sourceSocket th bytesPerRead conn
209 fromClient = sourceSocket th bytesPerRead conn
210 serveConnection' :: ResourceT IO ()
210 serveConnection' :: ResourceT IO ()
211 serveConnection' = do
211 serveConnection' = do
212− (len, env) <- fromClient C.$$ parseRequest port remoteHost'
212+ (len, env) <- parseRequest port remoteHost' fromClient
213 case settingsIntercept settings env of
213 case settingsIntercept settings env of
214 Nothing -> do
214 Nothing -> do
215 -- Let the application run for as long as it wants
215 -- Let the application run for as long as it wants
@@ -218,14 +218,16 @@ serveConnection settings th onException port app conn remoteHost' = do
218 liftIO $ T.resume th
218 liftIO $ T.resume th
219 keepAlive <- liftIO $ sendResponse th env conn res
219 keepAlive <- liftIO $ sendResponse th env conn res
220 if keepAlive then serveConnection' else return ()
220 if keepAlive then serveConnection' else return ()
221− Just intercept -> undefined {-do
221+ Just intercept -> error "intercept" {-do
222 liftIO $ T.pause th
222 liftIO $ T.pause th
223 intercept conn-}
223 intercept conn-}
225−parseRequest :: Port -> SockAddr -> C.Sink S.ByteString IO (Integer, Request)
225+parseRequest :: Port -> SockAddr
226+ -> C.Source IO S.ByteString
227+ -> ResourceT IO (Integer, Request)
226−parseRequest port remoteHost' = do
228+parseRequest port remoteHost' src = do
227− headers' <- takeHeaders
229+ headers' <- takeHeaders src
228− parseRequest' port headers' remoteHost'
230+ parseRequest' port headers' remoteHost' src
230-- FIXME come up with good values here
232-- FIXME come up with good values here
231bytesPerRead, maxTotalHeaderLength :: Int
233bytesPerRead, maxTotalHeaderLength :: Int
@@ -246,9 +248,10 @@ instance Exception InvalidRequest
246parseRequest' :: Port
248parseRequest' :: Port
247 -> [ByteString]
249 -> [ByteString]
248 -> SockAddr
250 -> SockAddr
251+ -> C.Source IO S.ByteString
249− -> C.Sink S.ByteString IO (Integer, Request)
252+ -> ResourceT IO (Integer, Request)
250−parseRequest' _ [] _ = throwIO $ NotEnoughLines []
253+parseRequest' _ [] _ _ = throwIO $ NotEnoughLines []
251−parseRequest' port (firstLine:otherLines) remoteHost' = do
254+parseRequest' port (firstLine:otherLines) remoteHost' src = do
252 (method, rpath', gets, httpversion) <- parseFirst firstLine
255 (method, rpath', gets, httpversion) <- parseFirst firstLine
253 let (host',rpath) =
256 let (host',rpath) =
254 if S.null rpath'
257 if S.null rpath'
@@ -277,6 +280,7 @@ parseRequest' port (firstLine:otherLines) remoteHost' = do
277 , requestHeaders = heads
280 , requestHeaders = heads
278 , isSecure = False
281 , isSecure = False
279 , remoteHost = remoteHost'
282 , remoteHost = remoteHost'
283+ , requestBody = src -- FIXME isolate
@@ -288,7 +292,7 @@ takeUntil c bs =
288{-# INLINE takeUntil #-}
292{-# INLINE takeUntil #-}
290parseFirst :: ByteString
294parseFirst :: ByteString
291− -> C.Sink S.ByteString IO (ByteString, ByteString, ByteString, H.HttpVersion)
295+ -> ResourceT IO (ByteString, ByteString, ByteString, H.HttpVersion)
292parseFirst s =
296parseFirst s =
293 case S.split 32 s of -- ' '
297 case S.split 32 s of -- ' '
294 [method, query, http'] -> do
298 [method, query, http'] -> do
@@ -420,7 +424,7 @@ sendResponse th req socket r = sendResponse' r
420 `mappend` chunkedTransferTerminator
424 `mappend` chunkedTransferTerminator
421 else (headers' False) `mappend` b
425 else (headers' False) `mappend` b
423− sendResponse' (ResponseEnumerator res) = undefined {-res enumResponse
427+ sendResponse' (ResponseEnumerator res) = error "sendResponse'" {-res enumResponse
425 enumResponse s hs = response True
429 enumResponse s hs = response True
@@ -522,10 +526,10 @@ defaultSettings = Settings
522 go' (Just ThreadKilled) = False
526 go' (Just ThreadKilled) = False
523 go' _ = True
527 go' _ = True
525−takeHeaders :: C.Sink ByteString IO [ByteString]
529+takeHeaders :: C.Source IO ByteString -> ResourceT IO [ByteString]
526−takeHeaders = do
530+takeHeaders src = do
527− !x <- forceHead ConnectionClosedByPeer
531+ !x <- forceHead ConnectionClosedByPeer src
528− takeHeaders' 0 id id x
532+ takeHeaders' 0 id id x src
530{-# INLINE takeHeaders #-}
534{-# INLINE takeHeaders #-}
@@ -533,17 +537,18 @@ takeHeaders' :: Int
533 -> ([ByteString] -> [ByteString])
537 -> ([ByteString] -> [ByteString])
534 -> ([ByteString] -> [ByteString])
538 -> ([ByteString] -> [ByteString])
535 -> ByteString
539 -> ByteString
540+ -> C.Source IO ByteString
536− -> C.Sink S.ByteString IO [ByteString]
541+ -> ResourceT IO [ByteString]
537−takeHeaders' !len _ _ _ | len > maxTotalHeaderLength = throwIO OverLargeHeader
542+takeHeaders' !len _ _ _ _ | len > maxTotalHeaderLength = throwIO OverLargeHeader
538−takeHeaders' !len !lines !prepend !bs = do
543+takeHeaders' !len !lines !prepend !bs src = do
539 let !bsLen = {-# SCC "takeHeaders'.bsLen" #-} S.length bs
544 let !bsLen = {-# SCC "takeHeaders'.bsLen" #-} S.length bs
540 !mnl = {-# SCC "takeHeaders'.mnl" #-} S.elemIndex 10 bs
545 !mnl = {-# SCC "takeHeaders'.mnl" #-} S.elemIndex 10 bs
541 case mnl of
546 case mnl of
542 -- no newline. prepend entire bs to next line
547 -- no newline. prepend entire bs to next line
543 !Nothing -> {-# SCC "takeHeaders'.noNewline" #-} do
548 !Nothing -> {-# SCC "takeHeaders'.noNewline" #-} do
544 let !len' = len + bsLen
549 let !len' = len + bsLen
545− !more <- forceHead IncompleteHeaders
550+ !more <- forceHead IncompleteHeaders src
546− takeHeaders' len' lines (prepend . (:) bs) more
551+ takeHeaders' len' lines (prepend . (:) bs) more src
547 Just !nl -> {-# SCC "takeHeaders'.newline" #-} do
552 Just !nl -> {-# SCC "takeHeaders'.newline" #-} do
548 let !end = nl
553 let !end = nl
549 !start = nl + 1
554 !start = nl + 1
@@ -561,7 +566,7 @@ takeHeaders' !len !lines !prepend !bs = do
561 if start < bsLen
566 if start < bsLen
562 then {-# SCC "takeHeaders'.noMoreHeaders.yield" #-} do
567 then {-# SCC "takeHeaders'.noMoreHeaders.yield" #-} do
563 let !rest = {-# SCC "takeHeaders'.noMoreHeaders.yield.rest" #-} SU.unsafeDrop start bs
568 let !rest = {-# SCC "takeHeaders'.noMoreHeaders.yield.rest" #-} SU.unsafeDrop start bs
564− undefined -- E.yield lines' $! E.Chunks [rest]
569+ error "yield" -- E.yield lines' $! E.Chunks [rest]
565 else return lines'
570 else return lines'
567 -- more headers
572 -- more headers
@@ -571,19 +576,18 @@ takeHeaders' !len !lines !prepend !bs = do
571 !more <- {-# SCC "takeHeaders'.more" #-}
576 !more <- {-# SCC "takeHeaders'.more" #-}
572 if start < bsLen
577 if start < bsLen
573 then return $! SU.unsafeDrop start bs
578 then return $! SU.unsafeDrop start bs
574− else forceHead IncompleteHeaders
579+ else forceHead IncompleteHeaders src
575− {-# SCC "takeHeaders'.takeMore" #-} takeHeaders' len' lines' id more
580+ {-# SCC "takeHeaders'.takeMore" #-} takeHeaders' len' lines' id more src
576{-# INLINE takeHeaders' #-}
581{-# INLINE takeHeaders' #-}
578−forceHead :: InvalidRequest -> C.Sink ByteString IO ByteString
583+forceHead :: InvalidRequest
584+ -> C.Source IO ByteString
585+ -> ResourceT IO ByteString
579−forceHead err = do
586+forceHead err src = do
582− !mx <- EL.head
587+ !mx <- src C.$$ CL.head
583 case mx of
588 case mx of
584− !Nothing -> E.throwError err
585 Just !x -> return x
589 Just !x -> return x
586− -}
590+ Nothing -> throwIO err
587{-# INLINE forceHead #-}
591{-# INLINE forceHead #-}
589checkCR :: ByteString -> Int -> Int
593checkCR :: ByteString -> Int -> Int