wai 3.0.2.3 → 3.0.3.0
raw patch · 2 files changed
+44/−17 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Network.Wai: ifRequest :: (Request -> Bool) -> Middleware -> Middleware
+ Network.Wai: mapResponseHeaders :: (ResponseHeaders -> ResponseHeaders) -> Response -> Response
+ Network.Wai: modifyResponse :: (Response -> Response) -> Middleware
Files
- Network/Wai.hs +43/−16
- wai.cabal +1/−1
Network/Wai.hs view
@@ -71,10 +71,15 @@ , responseLBS , responseStream , responseRaw- -- * Response accessors+ -- ** Response accessors , responseStatus , responseHeaders+ -- ** Response modifiers , responseToStream+ , mapResponseHeaders+ -- * Middleware composition+ , ifRequest+ , modifyResponse ) where import Blaze.ByteString.Builder (Builder, fromLazyByteString)@@ -225,6 +230,13 @@ (s, h, \withBody -> withBody $ \sendChunk _flush -> sendChunk b) responseToStream (ResponseRaw _ res) = responseToStream res +-- | Apply the provided function to the response header list of the Response.+mapResponseHeaders :: (H.ResponseHeaders -> H.ResponseHeaders) -> Response -> Response+mapResponseHeaders f (ResponseFile s h b1 b2) = ResponseFile s (f h) b1 b2+mapResponseHeaders f (ResponseBuilder s h b) = ResponseBuilder s (f h) b+mapResponseHeaders f (ResponseStream s h b) = ResponseStream s (f h) b+mapResponseHeaders _ r@(ResponseRaw _ _) = r+ ---------------------------------------------------------------- -- | The WAI application.@@ -242,21 +254,6 @@ -- @ type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived --- | Middleware is a component that sits between the server and application. It--- can do such tasks as GZIP encoding or response caching. What follows is the--- general definition of middleware, though a middleware author should feel--- free to modify this.------ 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 signature for this middleware--- might be:------ @ loadSession :: ([(String, String)] -> Application) -> Application @------ Here, instead of taking a standard 'Application' as its first argument, the--- middleware takes a function which consumes the session information as well.-type Middleware = Application -> Application -- | A default, blank request. --@@ -278,6 +275,36 @@ , requestHeaderHost = Nothing , requestHeaderRange = Nothing }+++-- | Middleware is a component that sits between the server and application. It+-- can do such tasks as GZIP encoding or response caching. What follows is the+-- general definition of middleware, though a middleware author should feel+-- free to modify this.+--+-- 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 signature for this middleware+-- might be:+--+-- @ loadSession :: ([(String, String)] -> Application) -> Application @+--+-- Here, instead of taking a standard 'Application' as its first argument, the+-- middleware takes a function which consumes the session information as well.+type Middleware = Application -> Application+++-- | apply a function that modifies a response as a 'Middleware'+modifyResponse :: (Response -> Response) -> Middleware+modifyResponse f app req respond = app req $ respond . f+++-- | conditionally apply a 'Middleware'+ifRequest :: (Request -> Bool) -> Middleware -> Middleware+ifRequest rpred middle app req | rpred req = middle app req+ | otherwise = app req++ -- | Get the request body as a lazy ByteString. However, do /not/ use any lazy -- I\/O, instead reading the entire body into memory strictly.
wai.cabal view
@@ -1,5 +1,5 @@ Name: wai-Version: 3.0.2.3+Version: 3.0.3.0 Synopsis: Web Application Interface. Description: Provides a common protocol for communication between web applications and web servers. description: API docs and the README are available at <http://www.stackage.org/package/wai>.