on master help sign in
Bump to 0.2.2
commit35ff4c5900c81d14f0f1b70dd0c35c40dee14d5f authorMichael Snoyman <michael@snoyman.com> dateSun 24 Oct 2010, 11:17 (16 years ago) parentdd1b31b
3 files changed+18−18
Network/Wai/Enumerator.hs+7−6 test.hs+9−10 wai.cabal+2−2
Network/Wai/Enumerator.hs+7−6
@@ -110,10 +110,10 @@ fromHandle h = Enumerator $ \iter a -> do
110110 Left a' -> return $ Left a'
111111 Right a' -> runEnumerator (fromHandle h) iter a'
112112
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.
114114fromHandleFinally :: Handle -> IO a -> Enumerator
115−fromHandleFinally h onEOF = Enumerator $ \iter a0 ->
116− finally (runEnumerator (fromHandle h) iter a0)
115+fromHandleFinally h onEOF = Enumerator $ \iter a0 ->
116+ finally (runEnumerator (fromHandle h) iter a0)
117117 onEOF
118118
119119-- | 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 ->
123123
124124-- | Wrapper around fromFile to perform an action after the file is closed.
125125fromFileFinally :: FilePath -> IO a -> Enumerator
126−fromFileFinally fp onClose = Enumerator $ \iter a0 ->
127− finally (runEnumerator (fromFile fp) iter a0)
126+fromFileFinally fp onClose = Enumerator $ \iter a0 ->
127+ finally (runEnumerator (fromFile fp) iter a0)
128128 onClose
129129
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.
131132fromTempFile :: FilePath -> Enumerator
132133fromTempFile fp = fromFileFinally fp $ removeFile fp
133134
test.hs+9−10
@@ -1,12 +1,12 @@
11{-# LANGUAGE Rank2Types #-}
2+{-# LANGUAGE OverloadedStrings #-}
23import Network.Wai
3−import Network.Wai.Enumerator (buffer)
4−import Network.Wai.Handler.SimpleServer
4+import Network.Wai.Handler.Webkit
55import qualified Data.ByteString.Char8 as B8
66import qualified Network.Wai.Source as Source
77
88main :: IO ()
9−main = putStrLn "http://localhost:3000/" >> run 3000 app
9+main = putStrLn "http://localhost:3000/" >> run "3000" app
1010
1111app :: Application
1212app req = case B8.unpack $ pathInfo req of
@@ -15,17 +15,16 @@ app req = case B8.unpack $ pathInfo req of
1515
1616indexResponse :: IO Response
1717indexResponse = return Response
18− { status = Status200
19− , responseHeaders = [(ContentType, B8.pack "text/html")]
18+ { status = status200
19+ , responseHeaders = [("Content-Type" , B8.pack "text/html")]
2020 , responseBody = index
2121 }
2222
2323postResponse :: Enumerator -> IO Response
2424postResponse rb = return Response
25− { status = Status200
26− , responseHeaders = [(ContentType, B8.pack "text/plain")]
27− , responseBody = Right $ buffer rb
25+ { status = status200
26+ , responseHeaders = [("Content-Type", B8.pack "text/plain")]
27+ , responseBody = ResponseEnumerator rb
2828 }
2929
30−index :: Either FilePath a
31−index = Left "index.html"
30+index = ResponseFile "index.html"
wai.cabal+2−2
@@ -1,5 +1,5 @@
11Name: wai
2−Version: 0.2.1
2+Version: 0.2.2
33Synopsis: Web Application Interface.
44Description: Provides a common protocol for communication between web aplications and web servers.
55License: BSD3
@@ -19,7 +19,7 @@ Source-repository head
1919Library
2020 Build-Depends: base >= 3 && < 5,
2121 bytestring >= 0.9 && < 0.10,
22− directory
22+ directory >= 1.0 && < 1.1
2323 Exposed-modules: Network.Wai
2424 Network.Wai.Enumerator
2525 Network.Wai.Source