@@ -16,15 +16,10 @@ module Network.Wai
1616 , Response (..)
1717 , Application
1818 , Middleware
19− , ResponseBody (..)
20− , ResponseBodyClass (..)
2119 ) where
2220
23−import qualified Data.ByteString.Lazy as L
2421import qualified Data.ByteString as B
2522import qualified Data.ByteString.Char8 as B8
26−import System.IO (withBinaryFile, IOMode (ReadMode), hIsEOF)
27−import Control.Monad (unless)
2823
2924-- | Please do not use the Show and Read instances for anything other than
3025-- debugging purposes. Instead, the 'methodFromBS' and 'methodToBS' provide a
@@ -108,29 +103,9 @@ data Response = Response
108103 { status :: Int
109104 , statusMessage :: B.ByteString
110105 , headers :: [(B.ByteString, B.ByteString)]
111− , body :: ResponseBody -> IO ()
106+ , body :: Either FilePath ((B.ByteString -> IO ()) -> IO ())
112107 }
113108
114109type Application = Request -> IO Response
115110
116111type Middleware = Application -> Application
117−
118−data ResponseBody = forall a. ResponseBodyClass a => ResponseBody a
119−class ResponseBodyClass a where
120− sendByteString :: a -> B.ByteString -> IO ()
121−
122− sendLazyByteString :: a -> L.ByteString -> IO ()
123− sendLazyByteString a bs = mapM_ (sendByteString a) $ L.toChunks bs
124−
125− sendFile :: a -> FilePath -> IO ()
126− sendFile a fp = withBinaryFile fp ReadMode helper where
127− helper h = do
128− eof <- hIsEOF h
129− unless eof $ do
130− b <- B.hGet h 1024 -- FIXME determine better block size
131− sendByteString a b
132− helper h
133−instance ResponseBodyClass ResponseBody where
134− sendByteString (ResponseBody a) = sendByteString a
135− sendLazyByteString (ResponseBody a) = sendLazyByteString a
136− sendFile (ResponseBody a) = sendFile a