wai-conduit (empty) → 3.0.0
raw patch · 4 files changed
+113/−0 lines, 4 filesdep +basedep +blaze-builderdep +bytestringsetup-changed
Dependencies added: base, blaze-builder, bytestring, conduit, http-types, transformers, wai
Files
- LICENSE +20/−0
- Network/Wai/Conduit.hs +67/−0
- Setup.hs +2/−0
- wai-conduit.cabal +24/−0
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2014 Michael Snoyman++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Network/Wai/Conduit.hs view
@@ -0,0 +1,67 @@+-- | A light-weight wrapper around @Network.Wai@ to provide easy conduit support.+module Network.Wai.Conduit+ ( -- * Request body+ sourceRequestBody+ -- * Response body+ , responseSource+ , responseRawSource+ -- * Re-export+ , module Network.Wai+ ) where++import Network.Wai+import Data.Conduit+import Control.Monad.IO.Class (MonadIO, liftIO)+import Data.ByteString (ByteString)+import qualified Data.ByteString as S+import Control.Monad (unless)+import Network.HTTP.Types+import Blaze.ByteString.Builder (Builder)+import Data.IORef+import qualified Data.Conduit.List as CL++-- | Stream the request body.+--+-- Since 3.0.0+sourceRequestBody :: MonadIO m => Request -> Source m ByteString+sourceRequestBody req =+ loop+ where+ go = liftIO (requestBody req)++ loop = do+ bs <- go+ unless (S.null bs) $ do+ yield bs+ loop++-- | Create an HTTP response out of a @Source@.+--+-- Since 3.0.0+responseSource :: Status -> ResponseHeaders -> Source IO (Flush Builder) -> Response+responseSource s hs src = responseStream s hs $ \send flush ->+ src $$ CL.mapM_ (\mbuilder ->+ case mbuilder of+ Chunk b -> send b+ Flush -> flush)++-- | Create a raw response using a @Source@ and @Sink@ to represent the input+-- and output, respectively.+--+-- Since 3.0.0+responseRawSource :: (MonadIO m, MonadIO n)+ => (Source m ByteString -> Sink ByteString n () -> IO ())+ -> Response+ -> Response+responseRawSource app backup =+ responseRaw app' backup+ where+ app' recv send =+ app src sink+ where+ src = do+ bs <- liftIO recv+ unless (S.null bs) $ do+ yield bs+ src+ sink = CL.mapM_ $ liftIO . send
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ wai-conduit.cabal view
@@ -0,0 +1,24 @@+name: wai-conduit+version: 3.0.0+synopsis: conduit wrappers for WAI+description: Since version 3.0.0, WAI has no built-in streaming data abstraction.+ This library provides similar functionality to what existed in WAI 2.x.+homepage: https://github.com/yesodweb/wai+license: MIT+license-file: LICENSE+author: Michael Snoyman+maintainer: michael@snoyman.com+category: Web, Conduit+build-type: Simple+cabal-version: >=1.10++library+ exposed-modules: Network.Wai.Conduit+ build-depends: base >= 4 && < 5+ , wai >= 3.0 && < 3.1+ , conduit+ , transformers+ , bytestring+ , http-types+ , blaze-builder+ default-language: Haskell2010