on master help sign in
Enumerator is now a type synonym
8618feaMichael Snoyman
Network/Wai.hs+3−4
@@ -24,7 +24,7 @@ module Network.Wai
24 , statusCode
24 , statusCode
25 , statusMessage
25 , statusMessage
26 -- * Enumerator
26 -- * Enumerator
27− , Enumerator (..)
27+ , Enumerator
28 -- * WAI interface
28 -- * WAI interface
29 , Request (..)
29 , Request (..)
30 , Response (..)
30 , Response (..)
@@ -235,8 +235,7 @@ statusMessage Status405 = B8.pack "Method Not Allowed"
235statusMessage Status500 = B8.pack "Internal Server Error"
235statusMessage Status500 = B8.pack "Internal Server Error"
236statusMessage (Status _ m) = m
236statusMessage (Status _ m) = m
237
237
238−data Enumerator = Enumerator (forall a.
239− ((a -> B.ByteString -> IO (Either a a)) -> a -> IO a))
238+type Enumerator a = (a -> B.ByteString -> IO (Either a a)) -> a -> IO a
240
239
241data Request = Request
240data Request = Request
242 { requestMethod :: Method
241 { requestMethod :: Method
@@ -255,7 +254,7 @@ data Request = Request
255data Response = Response
254data Response = Response
256 { status :: Status
255 { status :: Status
257 , headers :: [(ResponseHeader, B.ByteString)]
256 , headers :: [(ResponseHeader, B.ByteString)]
258− , body :: Either FilePath Enumerator
257+ , body :: forall a. Either FilePath (Enumerator a)
259 }
258 }
260
259
261type Application = Request -> IO Response
260type Application = Request -> IO Response
Network/Wai/Handler/SimpleServer.hs+2−3
@@ -21,7 +21,6 @@ import Network.Wai
21import qualified System.IO
21import qualified System.IO
22
22
23import qualified Data.ByteString as BS
23import qualified Data.ByteString as BS
24−import qualified Data.ByteString.Lazy as BL
25import qualified Data.ByteString.Char8 as B8
24import qualified Data.ByteString.Char8 as B8
26import Network
25import Network
27 ( listenOn, accept, sClose, PortID(PortNumber), Socket
26 ( listenOn, accept, sClose, PortID(PortNumber), Socket
@@ -167,9 +166,9 @@ sendResponse h res = do
167 BS.hPut h $ SL.pack "\r\n"
166 BS.hPut h $ SL.pack "\r\n"
168 case body res of
167 case body res of
169 Left fp -> unsafeSendFile h fp
168 Left fp -> unsafeSendFile h fp
170− Right (Enumerator enum) -> enum myPut h >> return ()
169+ Right enum -> enum myPut h >> return ()
171 where
170 where
172− myPut h bs = BS.hPut h bs >> return (Right h)
171+ myPut _ bs = BS.hPut h bs >> return (Right h)
173 putHeader (x, y) = do
172 putHeader (x, y) = do
174 BS.hPut h $ responseHeaderToBS x
173 BS.hPut h $ responseHeaderToBS x
175 BS.hPut h $ SL.pack ": "
174 BS.hPut h $ SL.pack ": "
test.hs+3−4
@@ -28,9 +28,8 @@ postResponse rb = return Response
28index :: Either FilePath a
28index :: Either FilePath a
29index = Left "index.html"
29index = Left "index.html"
30
30
31−postBody :: IO (Maybe B.ByteString) -> Enumerator
31+postBody :: IO (Maybe B.ByteString) -> Enumerator a
32−postBody req = Enumerator $ \f a -> helper f a where
32+postBody req f a = do
33− helper f a = do
34 mbs <- req
33 mbs <- req
35 case mbs of
34 case mbs of
36 Nothing -> return a
35 Nothing -> return a
@@ -38,4 +37,4 @@ postBody req = Enumerator $ \f a -> helper f a where
38 res <- f a bs
37 res <- f a bs
39 case res of
38 case res of
40 Left a' -> return a'
39 Left a' -> return a'
41− Right a' -> helper f a'
40+ Right a' -> postBody req f a'