@@ -38,6 +38,7 @@ import Data.Typeable (Typeable)
3838
3939import Network.Socket.SendFile
4040import Control.Arrow (first)
41+import Numeric (showHex)
4142
4243run :: Port -> Application -> IO ()
4344run port = withSocketsDo .
@@ -154,14 +155,23 @@ sendResponse httpversion h res = do
154155 B.hPut h $ statusMessage $ status res
155156 B.hPut h $ B.pack "\r\n"
156157 mapM_ putHeader $ responseHeaders res
158+ case responseBody res of
159+ ResponseFile _ -> return ()
160+ _ -> B.hPut h $ B.pack "Transfer-Encoding: chunked\r\n"
157161 B.hPut h $ B.pack "\r\n"
158162 case responseBody res of
159163 ResponseFile fp -> unsafeSendFile h fp
160− ResponseEnumerator (Enumerator enum) -> enum myPut h >> return ()
161− ResponseLBS lbs -> L.hPut h lbs
164+ ResponseEnumerator (Enumerator enum) ->
165+ enum (const myPut) h >> return ()
166+ ResponseLBS lbs -> mapM_ myPut $ L.toChunks lbs
167+ case responseBody res of
168+ ResponseFile _ -> return ()
169+ _ -> B.hPut h $ B.pack "0\r\n"
162170 where
163− myPut _ bs = do
171+ myPut bs = do
172+ B.hPut h $ B.pack $ showHex (B.length bs) "\r\n"
164173 B.hPut h bs
174+ B.hPut h $ B.pack "\r\n"
165175 return (Right h)
166176 putHeader (x, y) = do
167177 B.hPut h $ ciOriginal x