]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/ResponseWriter.hs
chunked output
[Lucu.git] / Network / HTTP / Lucu / ResponseWriter.hs
index f47e1f0fcb744dada3e486bd84c07bf469757880..266f825c4d8a0ce8e4d9190703d90dc050cc6a21 100644 (file)
@@ -15,13 +15,17 @@ import           Network.HTTP.Lucu.Interaction
 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 
@@ -104,14 +108,20 @@ responseWriter h tQueue
                                                   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