@@ -16,15 +16,10 @@ module Network.Wai
16 , Response (..)
16 , Response (..)
17 , Application
17 , Application
18 , Middleware
18 , Middleware
20− , ResponseBodyClass (..)
23−import qualified Data.ByteString.Lazy as L
24import qualified Data.ByteString as B
21import qualified Data.ByteString as B
25import qualified Data.ByteString.Char8 as B8
22import qualified Data.ByteString.Char8 as B8
26−import System.IO (withBinaryFile, IOMode (ReadMode), hIsEOF)
27−import Control.Monad (unless)
29-- | Please do not use the Show and Read instances for anything other than
24-- | Please do not use the Show and Read instances for anything other than
30-- debugging purposes. Instead, the 'methodFromBS' and 'methodToBS' provide a
25-- debugging purposes. Instead, the 'methodFromBS' and 'methodToBS' provide a
@@ -108,29 +103,9 @@ data Response = Response
108 { status :: Int
103 { status :: Int
109 , statusMessage :: B.ByteString
104 , statusMessage :: B.ByteString
110 , headers :: [(B.ByteString, B.ByteString)]
105 , headers :: [(B.ByteString, B.ByteString)]
111− , body :: ResponseBody -> IO ()
106+ , body :: Either FilePath ((B.ByteString -> IO ()) -> IO ())
114type Application = Request -> IO Response
109type Application = Request -> IO Response
116type Middleware = Application -> Application
111type Middleware = Application -> Application
118−data ResponseBody = forall a. ResponseBodyClass a => ResponseBody a
119−class ResponseBodyClass a where
120− sendByteString :: a -> B.ByteString -> IO ()
122− sendLazyByteString :: a -> L.ByteString -> IO ()
123− sendLazyByteString a bs = mapM_ (sendByteString a) $ L.toChunks bs
125− sendFile :: a -> FilePath -> IO ()
126− sendFile a fp = withBinaryFile fp ReadMode helper where
130− b <- B.hGet h 1024 -- FIXME determine better block size
133−instance ResponseBodyClass ResponseBody where
134− sendByteString (ResponseBody a) = sendByteString a
135− sendLazyByteString (ResponseBody a) = sendLazyByteString a
136− sendFile (ResponseBody a) = sendFile a