on master help sign in
Bump to 0.2.2
35ff4c5Michael Snoyman
Network/Wai/Enumerator.hs+7−6
@@ -110,10 +110,10 @@ fromHandle h = Enumerator $ \iter a -> do
110 Left a' -> return $ Left a'
110 Left a' -> return $ Left a'
111 Right a' -> runEnumerator (fromHandle h) iter a'
111 Right a' -> runEnumerator (fromHandle h) iter a'
112
112
113−-- | Wrapper around fromHandle to perform an action after EOF or an exception
113+-- | Wrapper around fromHandle to perform an action after EOF or an exception.
114fromHandleFinally :: Handle -> IO a -> Enumerator
114fromHandleFinally :: Handle -> IO a -> Enumerator
115−fromHandleFinally h onEOF = Enumerator $ \iter a0 ->
115+fromHandleFinally h onEOF = Enumerator $ \iter a0 ->
116− finally (runEnumerator (fromHandle h) iter a0)
116+ finally (runEnumerator (fromHandle h) iter a0)
117 onEOF
117 onEOF
118
118
119-- | A little wrapper around 'fromHandle' which first opens a file for reading.
119-- | A little wrapper around 'fromHandle' which first opens a file for reading.
@@ -123,11 +123,12 @@ fromFile fp = Enumerator $ \iter a0 -> withBinaryFile fp ReadMode $ \h ->
123
123
124-- | Wrapper around fromFile to perform an action after the file is closed.
124-- | Wrapper around fromFile to perform an action after the file is closed.
125fromFileFinally :: FilePath -> IO a -> Enumerator
125fromFileFinally :: FilePath -> IO a -> Enumerator
126−fromFileFinally fp onClose = Enumerator $ \iter a0 ->
126+fromFileFinally fp onClose = Enumerator $ \iter a0 ->
127− finally (runEnumerator (fromFile fp) iter a0)
127+ finally (runEnumerator (fromFile fp) iter a0)
128 onClose
128 onClose
129
129
130−-- | Enumerator to read and remove a file
130+-- | Enumerator to read and remove a file. Being based on 'fromFileFinally', it
131+-- ensures the file is removed, even in the presence of exceptions.
131fromTempFile :: FilePath -> Enumerator
132fromTempFile :: FilePath -> Enumerator
132fromTempFile fp = fromFileFinally fp $ removeFile fp
133fromTempFile fp = fromFileFinally fp $ removeFile fp
133
134
test.hs+9−10
@@ -1,12 +1,12 @@
1{-# LANGUAGE Rank2Types #-}
1{-# LANGUAGE Rank2Types #-}
2+{-# LANGUAGE OverloadedStrings #-}
2import Network.Wai
3import Network.Wai
3−import Network.Wai.Enumerator (buffer)
4+import Network.Wai.Handler.Webkit
4−import Network.Wai.Handler.SimpleServer
5import qualified Data.ByteString.Char8 as B8
5import qualified Data.ByteString.Char8 as B8
6import qualified Network.Wai.Source as Source
6import qualified Network.Wai.Source as Source
7
7
8main :: IO ()
8main :: IO ()
9−main = putStrLn "http://localhost:3000/" >> run 3000 app
9+main = putStrLn "http://localhost:3000/" >> run "3000" app
10
10
11app :: Application
11app :: Application
12app req = case B8.unpack $ pathInfo req of
12app req = case B8.unpack $ pathInfo req of
@@ -15,17 +15,16 @@ app req = case B8.unpack $ pathInfo req of
15
15
16indexResponse :: IO Response
16indexResponse :: IO Response
17indexResponse = return Response
17indexResponse = return Response
18− { status = Status200
18+ { status = status200
19− , responseHeaders = [(ContentType, B8.pack "text/html")]
19+ , responseHeaders = [("Content-Type" , B8.pack "text/html")]
20 , responseBody = index
20 , responseBody = index
21 }
21 }
22
22
23postResponse :: Enumerator -> IO Response
23postResponse :: Enumerator -> IO Response
24postResponse rb = return Response
24postResponse rb = return Response
25− { status = Status200
25+ { status = status200
26− , responseHeaders = [(ContentType, B8.pack "text/plain")]
26+ , responseHeaders = [("Content-Type", B8.pack "text/plain")]
27− , responseBody = Right $ buffer rb
27+ , responseBody = ResponseEnumerator rb
28 }
28 }
29
29
30−index :: Either FilePath a
31−index = Left "index.html"
30+index = ResponseFile "index.html"
wai.cabal+2−2
@@ -1,5 +1,5 @@
1Name: wai
1Name: wai
2−Version: 0.2.1
2+Version: 0.2.2
3Synopsis: Web Application Interface.
3Synopsis: Web Application Interface.
4Description: Provides a common protocol for communication between web aplications and web servers.
4Description: Provides a common protocol for communication between web aplications and web servers.
5License: BSD3
5License: BSD3
@@ -19,7 +19,7 @@ Source-repository head
19Library
19Library
20 Build-Depends: base >= 3 && < 5,
20 Build-Depends: base >= 3 && < 5,
21 bytestring >= 0.9 && < 0.10,
21 bytestring >= 0.9 && < 0.10,
22− directory
22+ directory >= 1.0 && < 1.1
23 Exposed-modules: Network.Wai
23 Exposed-modules: Network.Wai
24 Network.Wai.Enumerator
24 Network.Wai.Enumerator
25 Network.Wai.Source
25 Network.Wai.Source