wai 2.0.0 → 2.1.0
raw patch · 3 files changed
+29/−9 lines, 3 filesdep ~vault
Dependency ranges changed: vault
Files
- Network/Wai.hs +23/−3
- Network/Wai/Internal.hs +4/−4
- wai.cabal +2/−2
Network/Wai.hs view
@@ -5,7 +5,7 @@ This module defines a generic web application interface. It is a common protocol between web servers and web applications. -The overriding design principles here are performance and generality . To+The overriding design principles here are performance and generality. To address performance, this library is built on top of the conduit and blaze-builder packages. The advantages of conduits over lazy IO have been debated elsewhere and so will not be addressed here. However, helper functions@@ -36,7 +36,7 @@ -} module Network.Wai (- -- * Ttypes+ -- * Types Application , Middleware -- * Request@@ -69,6 +69,7 @@ , responseLBS , responseSource , responseSourceBracket+ , responseRaw -- * Response accessors , responseStatus , responseHeaders@@ -153,6 +154,22 @@ return $ ResponseSource st hdr $ \f -> bracket (return resource) teardown (\_ -> f src) +-- | Create a response for a raw application. This is useful for \"upgrade\"+-- situations such as WebSockets, where an application requests for the server+-- to grant it raw network access.+--+-- This function requires a backup response to be provided, for the case where+-- the handler in question does not support such upgrading (e.g., CGI apps).+--+-- In the event that you read from the request body before returning a+-- @responseRaw@, behavior is undefined.+--+-- Since 2.1.0+responseRaw :: (C.Source IO B.ByteString -> C.Sink B.ByteString IO () -> IO ())+ -> Response+ -> Response+responseRaw rawApp fallback = ResponseRaw ($ rawApp) fallback+ ---------------------------------------------------------------- -- | Accessing 'H.Status' in 'Response'.@@ -160,12 +177,14 @@ responseStatus (ResponseFile s _ _ _) = s responseStatus (ResponseBuilder s _ _ ) = s responseStatus (ResponseSource s _ _ ) = s+responseStatus (ResponseRaw _ res ) = responseStatus res -- | Accessing 'H.Status' in 'Response'. responseHeaders :: Response -> H.ResponseHeaders responseHeaders (ResponseFile _ hs _ _) = hs responseHeaders (ResponseBuilder _ hs _ ) = hs responseHeaders (ResponseSource _ hs _ ) = hs+responseHeaders (ResponseRaw _ res) = responseHeaders res -- | Converting the body information in 'Response' to 'Source'. responseToSource :: Response@@ -177,6 +196,7 @@ (s, h, \f -> IO.withFile fp IO.ReadMode $ \handle -> f $ CB.sourceHandle handle C.$= CL.map (C.Chunk . fromByteString)) responseToSource (ResponseBuilder s h b) = (s, h, ($ CL.sourceList [C.Chunk b]))+responseToSource (ResponseRaw _ res) = responseToSource res sourceFilePart :: IO.Handle -> FilePart -> C.Source IO B.ByteString sourceFilePart handle (FilePart offset count _) =@@ -194,7 +214,7 @@ -- -- As an example of an alternate type for middleware, suppose you write a -- function to load up session information. The session information is simply a--- string map \[(String, String)\]. A logical type signatures for this middleware+-- string map \[(String, String)\]. A logical type signature for this middleware -- might be: -- -- @ loadSession :: ([(String, String)] -> Application) -> Application @
Network/Wai/Internal.hs view
@@ -11,11 +11,7 @@ import qualified Data.Conduit as C import Data.Text (Text) import Data.Typeable (Typeable)-#if MIN_VERSION_vault(0,3,0) import Data.Vault.Lazy (Vault)-#else-import Data.Vault (Vault)-#endif import Data.Word (Word64) import qualified Network.HTTP.Types as H import Network.Socket (SockAddr)@@ -87,7 +83,11 @@ = ResponseFile H.Status H.ResponseHeaders FilePath (Maybe FilePart) | ResponseBuilder H.Status H.ResponseHeaders Builder | ResponseSource H.Status H.ResponseHeaders (forall b. WithSource IO (C.Flush Builder) b)+ | ResponseRaw (forall b. WithRawApp b) Response deriving Typeable++type RawApp = C.Source IO B.ByteString -> C.Sink B.ByteString IO () -> IO ()+type WithRawApp b = (RawApp -> IO b) -> IO b -- | Auxiliary type for 'ResponseSource'. type WithSource m a b = (C.Source m a -> m b) -> m b
wai.cabal view
@@ -1,5 +1,5 @@ Name: wai-Version: 2.0.0+Version: 2.1.0 Synopsis: Web Application Interface. Description: Provides a common protocol for communication between web applications and web servers. License: MIT@@ -25,7 +25,7 @@ , http-types >= 0.7 , text >= 0.7 , transformers >= 0.2.2- , vault >= 0.1 && < 0.4+ , vault >= 0.3 && < 0.4 Exposed-modules: Network.Wai Network.Wai.Internal ghc-options: -Wall