import Network.HTTP.Lucu.Response
import Prelude hiding (catch)
import System.IO
+import Text.Printf
import Debug.Trace
responseWriter :: Handle -> InteractionQueue -> IO ()
responseWriter h tQueue
- = awaitSomethingToWrite
+ = catch awaitSomethingToWrite $ \ exc ->
+ case exc of
+ IOException _ -> return ()
+ _ -> print exc
where
awaitSomethingToWrite :: IO ()
awaitSomethingToWrite
return chunk
unless willDiscardBody
$ do if willChunkBody then
- fail "FIXME: not implemented"
+ do hPrintf h "%x\r\n" (toInteger $ B.length chunk)
+ B.hPut h chunk
+ hPutStr h "\r\n"
else
B.hPut h chunk
hFlush h
awaitSomethingToWrite
finishBodyChunk :: Interaction -> IO ()
- finishBodyChunk itr = return () -- FIXME: not implemented
+ finishBodyChunk itr
+ = do willDiscardBody <- atomically $ readItr itr itrWillDiscardBody id
+ willChunkBody <- atomically $ readItr itr itrWillChunkBody id
+ when (not willDiscardBody && willChunkBody)
+ $ hPutStr h "0\r\n" >> hFlush h
finalize :: Interaction -> IO ()
finalize itr
import Network.HTTP.Lucu.Config
import Network.HTTP.Lucu.Httpd
import Network.HTTP.Lucu.Resource
+import System.Posix.Signals
main :: IO ()
main = let config = defaultConfig { cnfServerPort = PortNumber 9999 }
resources = mkResTree []
in
- runHttpd config resources
\ No newline at end of file
+ do installHandler sigPIPE Ignore Nothing
+ runHttpd config resources
\ No newline at end of file