]> gitweb @ CieloNegro.org - Lucu.git/commitdiff
chunked output
authorpho <pho@cielonegro.org>
Sat, 31 Mar 2007 05:04:23 +0000 (14:04 +0900)
committerpho <pho@cielonegro.org>
Sat, 31 Mar 2007 05:04:23 +0000 (14:04 +0900)
darcs-hash:20070331050423-62b54-f774f4a48d9bf77adf6b88339561ecfa9ece2dbc.gz

Network/HTTP/Lucu/ResponseWriter.hs
examples/HelloWorld.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
index d5b8d701318b5a5bccb7e7e275a3fab108c29733..fe5b543e4f34bbfa20bb4f95439c2aabe580bbb0 100644 (file)
@@ -2,9 +2,11 @@ import Network
 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