pipes-wai (empty) → 3.0.0
raw patch · 4 files changed
+120/−0 lines, 4 filesdep +basedep +blaze-builderdep +bytestringsetup-changed
Dependencies added: base, blaze-builder, bytestring, http-types, pipes, transformers, wai
Files
- LICENSE +20/−0
- Pipes/Wai.hs +73/−0
- Setup.hs +2/−0
- pipes-wai.cabal +25/−0
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2014 Ian Duncan++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.
+ Pipes/Wai.hs view
@@ -0,0 +1,73 @@+-- | A light-weight wrapper around @Network.Wai@ to provide easy conduit support.+module Pipes.Wai+ ( -- * Request body+ producerRequestBody+ -- * Response body+ , responseProducer+ , responseRawProducer+ -- * Re-export+ , module Network.Wai+ ) where++import Network.Wai+import Pipes+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 Pipes.Prelude as CL++data Flush a = Chunk a | Flush+ deriving (Eq, Ord, Show)++instance Functor Flush where+ fmap f c = case c of+ Chunk a -> Chunk $ f a+ Flush -> Flush++-- | Stream the request body.+--+-- Since 3.0.0+producerRequestBody :: MonadIO m => Request -> Producer ByteString m ()+producerRequestBody 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 @Producer@.+--+-- Since 3.0.0+responseProducer :: Status -> ResponseHeaders -> Producer (Flush Builder) IO () -> Response+responseProducer s hs src = responseStream s hs $ \send flush ->+ runEffect $ for src $ \mbuilder -> case mbuilder of+ Chunk b -> lift $ send b+ Flush -> lift $ flush++-- | Create a raw response using a @Source@ and @Sink@ to represent the input+-- and output, respectively.+--+-- Since 3.0.0+responseRawProducer :: (MonadIO m, MonadIO n)+ => (Producer ByteString m () -> Consumer ByteString n () -> IO ())+ -> Response+ -> Response+responseRawProducer app = responseRaw app'+ where+ app' recv send =+ app src sink+ where+ src = do+ bs <- liftIO recv+ unless (S.null bs) $ do+ yield bs+ src+ sink = (await >>= liftIO . send) >> sink
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pipes-wai.cabal view
@@ -0,0 +1,25 @@+-- Initial pipes-wai.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++name: pipes-wai+version: 3.0.0+synopsis: A port of wai-conduit for the pipes ecosystem+-- description: +homepage: http://github.com/brewtown/pipes-wai+license: MIT+license-file: LICENSE+author: Ian Duncan+maintainer: ian@iankduncan.com+-- copyright: +category: Web, Pipes+build-type: Simple+-- extra-source-files: +cabal-version: >=1.10++library+ exposed-modules: Pipes.Wai+ -- other-modules: + -- other-extensions: + build-depends: base == 4.*, wai ==3.0.*, pipes >=4, transformers, bytestring, http-types, blaze-builder+ -- hs-source-dirs: + default-language: Haskell2010