on master help sign in
wai is complete
960cef5Michael Snoyman
wai/Network/Wai.hs+21−20
@@ -39,8 +39,8 @@ module Network.Wai
39 ( -- * WAI interface
39 ( -- * WAI interface
40 Request (..)
40 Request (..)
41 , Response (..)
41 , Response (..)
42− , ResponseEnumerator
42+ , ResponseStream
43− , responseEnumerator
43+ , responseStream
44 , Application
44 , Application
45 , Middleware
45 , Middleware
46 , FilePart (..)
46 , FilePart (..)
@@ -53,11 +53,15 @@ import qualified Data.ByteString.Lazy as L
53import Data.Typeable (Typeable)
53import Data.Typeable (Typeable)
54import Control.Monad.Trans.Resource (ResourceT)
54import Control.Monad.Trans.Resource (ResourceT)
55import qualified Data.Conduit as C
55import qualified Data.Conduit as C
56+import qualified Data.Conduit.List as CL
57+import qualified Data.Conduit.Binary as CB
56import Blaze.ByteString.Builder (Builder, fromLazyByteString)
58import Blaze.ByteString.Builder (Builder, fromLazyByteString)
57import Network.Socket (SockAddr)
59import Network.Socket (SockAddr)
58import qualified Network.HTTP.Types as H
60import qualified Network.HTTP.Types as H
59import Data.Text (Text)
61import Data.Text (Text)
60import Data.ByteString.Lazy.Char8 () -- makes it easier to use responseLBS
62import Data.ByteString.Lazy.Char8 () -- makes it easier to use responseLBS
63+import Blaze.ByteString.Builder (fromByteString)
64+import Filesystem.Path.CurrentOS (decodeString)
61
65
62-- | Information on the request sent by the client. This abstracts away the
66-- | Information on the request sent by the client. This abstracts away the
63-- details of the underlying implementation.
67-- details of the underlying implementation.
@@ -99,7 +103,7 @@ data Request = Request
99data Response
103data Response
100 = ResponseFile H.Status H.ResponseHeaders FilePath (Maybe FilePart)
104 = ResponseFile H.Status H.ResponseHeaders FilePath (Maybe FilePart)
101 | ResponseBuilder H.Status H.ResponseHeaders Builder
105 | ResponseBuilder H.Status H.ResponseHeaders Builder
102− | ResponseEnumerator (forall a. ResponseEnumerator a)
106+ | ResponseStream (forall a. ResponseStream a)
103 deriving Typeable
107 deriving Typeable
104
108
105data FilePart = FilePart
109data FilePart = FilePart
@@ -131,25 +135,22 @@ data FilePart = FilePart
131-- A3. You can force blaze-builder to output a ByteString before it is an
135-- A3. You can force blaze-builder to output a ByteString before it is an
132-- optimal size by sending a flush command.
136-- optimal size by sending a flush command.
133
137
134−type ResponseEnumerator a =
138+type ResponseStream a =
135− (H.Status -> H.ResponseHeaders -> C.Sink Builder IO a)
139+ (H.Status -> H.ResponseHeaders -> C.SinkM Builder IO a)
136 -> ResourceT IO a
140 -> ResourceT IO a
137
141
138−responseEnumerator :: Response -> ResponseEnumerator a
142+responseStream :: Response -> ResponseStream a
139−responseEnumerator = undefined
143+responseStream (ResponseStream e) f = e f
140−{-
141−responseEnumerator (ResponseEnumerator e) f = e f
142−responseEnumerator (ResponseFile s h fp mpart) f =
144+responseStream (ResponseFile s h fp (Just part)) f =
143− run_ $ (maybe enumFile enumFilePart) mpart fp $$ joinI
145+ sourceFilePart part fp C.$$ CL.map fromByteString C.=$ f s h
146+responseStream (ResponseFile s h fp Nothing) f =
144− $ EL.map fromByteString $$ f s h
147+ CB.sourceFile (decodeString fp) C.$$ CL.map fromByteString C.=$ f s h
145−responseEnumerator (ResponseBuilder s h b) f = run_ $ do
148+responseStream (ResponseBuilder s h b) f =
146− E.yield () $ E.Chunks [b]
149+ CL.fromList [b] C.$$ f s h
147− f s h
150+
148−
149−enumFilePart :: FilePart -> FilePath -> C.Source IO B.ByteString
151+sourceFilePart :: FilePart -> FilePath -> C.SourceM IO B.ByteString
150−enumFilePart (FilePart offset count) fp =
152+sourceFilePart (FilePart offset count) fp =
151− enumFileRange fp (Just offset) (Just count)
153+ CB.sourceFileRange (decodeString fp) (Just offset) (Just count)
152−-}
153
154
154responseLBS :: H.Status -> H.ResponseHeaders -> L.ByteString -> Response
155responseLBS :: H.Status -> H.ResponseHeaders -> L.ByteString -> Response
155responseLBS s h = ResponseBuilder s h . fromLazyByteString
156responseLBS s h = ResponseBuilder s h . fromLazyByteString
wai/wai.cabal+2−1
@@ -1,5 +1,5 @@
1Name: wai
1Name: wai
2−Version: 0.5.0
2+Version: 1.0.0
3Synopsis: Web Application Interface.
3Synopsis: Web Application Interface.
4Description: Provides a common protocol for communication between web applications and web servers.
4Description: Provides a common protocol for communication between web applications and web servers.
5License: BSD3
5License: BSD3
@@ -25,5 +25,6 @@ Library
25 , http-types >= 0.6 && < 0.7
25 , http-types >= 0.6 && < 0.7
26 , text >= 0.7 && < 0.12
26 , text >= 0.7 && < 0.12
27 , transformers >= 0.2.2 && < 0.3
27 , transformers >= 0.2.2 && < 0.3
28+ , system-filepath >= 0.4.3 && < 0.5
28 Exposed-modules: Network.Wai
29 Exposed-modules: Network.Wai
29 ghc-options: -Wall
30 ghc-options: -Wall