on master help sign in
Fix up some docs for 3.0 #262
commitf547e52f9df04aabafe0b7f1fb7028a7e825410f authorMichael Snoyman <michael@snoyman.com> dateTue 10 Jun 2014, 16:21 (12 years ago) parent4c29ebb
3 files changed+17−13
wai/Network/Wai.hs+16−2 wai/Network/Wai/Internal.hs−10 wai/wai.cabal+1−1
wai/Network/Wai.hs+16−2
@@ -129,7 +129,9 @@ responseBuilder = ResponseBuilder
129129responseLBS :: H.Status -> H.ResponseHeaders -> L.ByteString -> Response
130130responseLBS s h = ResponseBuilder s h . fromLazyByteString
131131
132−-- | Creating 'Response' from 'C.Source'.
132+-- | Creating 'Response' from a stream of values.
133+--
134+-- Since 3.0.0
133135responseStream :: H.Status
134136 -> H.ResponseHeaders
135137 -> StreamingBody
@@ -168,7 +170,7 @@ responseHeaders (ResponseBuilder _ hs _ ) = hs
168170responseHeaders (ResponseStream _ hs _ ) = hs
169171responseHeaders (ResponseRaw _ res) = responseHeaders res
170172
171−-- | Converting the body information in 'Response' to 'Source'.
173+-- | Converting the body information in 'Response' to a @StreamingBody@.
172174responseToStream :: Response
173175 -> ( H.Status
174176 , H.ResponseHeaders
@@ -206,6 +208,18 @@ responseToStream (ResponseRaw _ res) = responseToStream res
206208----------------------------------------------------------------
207209
208210-- | The WAI application.
211+--
212+-- Note that, since WAI 3.0, this type is structured in continuation passing
213+-- style to allow for proper safe resource handling. This was handled in the
214+-- past via other means (e.g., @ResourceT@). As a demonstration:
215+--
216+-- @
217+-- app :: Application
218+-- app req respond = bracket_
219+-- (putStrLn "Allocating scarce resource")
220+-- (putStrLn "Cleaning up")
221+-- (respond $ responseLBS status200 [] "Hello World")
222+-- @
209223type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
210224
211225-- | Middleware is a component that sits between the server and application. It
wai/Network/Wai/Internal.hs−10
@@ -71,16 +71,6 @@ data Request = Request {
7171 }
7272 deriving (Typeable)
7373
74−-- | The strange structure of the third field or ResponseSource is to allow for
75−-- exception-safe resource allocation. As an example:
76−--
77−-- > app :: Application
78−-- > app _ = return $ ResponseSource status200 [] $ \f -> bracket
79−-- > (putStrLn "Allocation" >> return 5)
80−-- > (\i -> putStrLn $ "Cleaning up: " ++ show i)
81−-- > (\_ -> f $ do
82−-- > yield $ Chunk $ fromByteString "Hello "
83−-- > yield $ Chunk $ fromByteString "World!")
8474data Response
8575 = ResponseFile H.Status H.ResponseHeaders FilePath (Maybe FilePart)
8676 | ResponseBuilder H.Status H.ResponseHeaders Builder
wai/wai.cabal+1−1
@@ -1,5 +1,5 @@
11Name: wai
2−Version: 3.0.0
2+Version: 3.0.0.1
33Synopsis: Web Application Interface.
44Description: Provides a common protocol for communication between web applications and web servers.
55License: MIT