packages feed

wai 0.3.2 → 0.4.0

raw patch · 2 files changed

+71/−199 lines, 2 filesdep +http-typesdep +textdep +transformersdep ~basedep ~blaze-builderdep ~enumeratorPVP ok

version bump matches the API change (PVP)

Dependencies added: http-types, text, transformers

Dependency ranges changed: base, blaze-builder, enumerator

API changes (from Hackage documentation)

- Network.Wai: CIByteString :: !ByteString -> !ByteString -> CIByteString
- Network.Wai: Status :: Int -> ByteString -> Status
- Network.Wai: ciLowerCase :: CIByteString -> !ByteString
- Network.Wai: ciOriginal :: CIByteString -> !ByteString
- Network.Wai: data CIByteString
- Network.Wai: data Status
- Network.Wai: errorHandler :: Request -> String -> IO ()
- Network.Wai: http09 :: HttpVersion
- Network.Wai: http10 :: HttpVersion
- Network.Wai: http11 :: HttpVersion
- Network.Wai: instance Data CIByteString
- Network.Wai: instance Eq CIByteString
- Network.Wai: instance Eq Status
- Network.Wai: instance IsString CIByteString
- Network.Wai: instance Ord CIByteString
- Network.Wai: instance Read CIByteString
- Network.Wai: instance Show CIByteString
- Network.Wai: instance Show Status
- Network.Wai: instance Typeable CIByteString
- Network.Wai: mkCIByteString :: ByteString -> CIByteString
- Network.Wai: status200 :: Status
- Network.Wai: status201 :: Status
- Network.Wai: status206 :: Status
- Network.Wai: status301 :: Status
- Network.Wai: status302 :: Status
- Network.Wai: status303 :: Status
- Network.Wai: status400 :: Status
- Network.Wai: status401 :: Status
- Network.Wai: status403 :: Status
- Network.Wai: status404 :: Status
- Network.Wai: status405 :: Status
- Network.Wai: status500 :: Status
- Network.Wai: statusBadRequest :: Status
- Network.Wai: statusCode :: Status -> Int
- Network.Wai: statusCreated :: Status
- Network.Wai: statusForbidden :: Status
- Network.Wai: statusFound :: Status
- Network.Wai: statusMessage :: Status -> ByteString
- Network.Wai: statusMovedPermanently :: Status
- Network.Wai: statusNotAllowed :: Status
- Network.Wai: statusNotFound :: Status
- Network.Wai: statusOK :: Status
- Network.Wai: statusPartialContent :: Status
- Network.Wai: statusSeeOther :: Status
- Network.Wai: statusServerError :: Status
- Network.Wai: statusUnauthorized :: Status
- Network.Wai: type HttpVersion = ByteString
- Network.Wai: type Method = ByteString
- Network.Wai: type RequestHeader = CIByteString
- Network.Wai: type RequestHeaders = [(RequestHeader, ByteString)]
- Network.Wai: type ResponseHeader = CIByteString
- Network.Wai: type ResponseHeaders = [(ResponseHeader, ByteString)]
+ Network.Wai: FilePart :: Integer -> Integer -> FilePart
+ Network.Wai: data FilePart
+ Network.Wai: filePartByteCount :: FilePart -> Integer
+ Network.Wai: filePartOffset :: FilePart -> Integer
+ Network.Wai: rawPathInfo :: Request -> ByteString
+ Network.Wai: rawQueryString :: Request -> ByteString
- Network.Wai: Request :: Method -> HttpVersion -> ByteString -> ByteString -> ByteString -> Int -> [(RequestHeader, ByteString)] -> Bool -> (String -> IO ()) -> SockAddr -> Request
+ Network.Wai: Request :: Method -> HttpVersion -> ByteString -> ByteString -> ByteString -> Int -> RequestHeaders -> Bool -> SockAddr -> [Text] -> Query -> Request
- Network.Wai: ResponseFile :: Status -> ResponseHeaders -> FilePath -> Response
+ Network.Wai: ResponseFile :: Status -> ResponseHeaders -> FilePath -> (Maybe FilePart) -> Response
- Network.Wai: pathInfo :: Request -> ByteString
+ Network.Wai: pathInfo :: Request -> [Text]
- Network.Wai: queryString :: Request -> ByteString
+ Network.Wai: queryString :: Request -> Query
- Network.Wai: requestHeaders :: Request -> [(RequestHeader, ByteString)]
+ Network.Wai: requestHeaders :: Request -> RequestHeaders

Files

Network/Wai.hs view
@@ -7,253 +7,122 @@ protocol between web servers and web applications.  The overriding design principles here are performance and generality . To-address performance, this library is built on top of the enumerator package.-The advantages of this approach over lazy IO have been debated elsewhere.-However, helper functions like 'responseLBS' allow you to continue using lazy-IO if you so desire.+address performance, this library is built on top of the enumerator and+blaze-builder packages.  The advantages of enumerators over lazy IO have been+debated elsewhere and so will not be addressed here.  However, helper functions+like 'responseLBS' allow you to continue using lazy IO if you so desire.  Generality is achieved by removing many variables commonly found in similar projects that are not universal to all servers. The goal is that the 'Request' object contains only data which is meaningful in all circumstances. -A final note: please remember when using this package that, while your-application may compile without a hitch against many different servers, there-are other considerations to be taken when moving to a new backend. For example,-if you transfer from a CGI application to a FastCGI one, you might suddenly-find you have a memory leak. Conversely, a FastCGI application would be-well served to preload all templates from disk when first starting; this-would kill the performance of a CGI application.+Please remember when using this package that, while your application may+compile without a hitch against many different servers, there are other+considerations to be taken when moving to a new backend. For example, if you+transfer from a CGI application to a FastCGI one, you might suddenly find you+have a memory leak. Conversely, a FastCGI application would be well served to+preload all templates from disk when first starting; this would kill the+performance of a CGI application. +This package purposely provides very little functionality. You can find various+middlewares, backends and utilities on Hackage. Some of the most commonly used+include:++[warp] <http://hackage.haskell.org/package/warp>++[wai-extra] <http://hackage.haskell.org/package/wai-extra>++[wai-test] <http://hackage.haskell.org/package/wai-test>+ -} module Network.Wai-    ( -- * Data types--      -- ** Request method-      Method-      -- ** HTTP protocol versions-    , HttpVersion-    , http09-    , http10-    , http11-      -- ** Case-insensitive byte strings-    , CIByteString (..)-    , mkCIByteString-      -- ** Request header names-    , RequestHeader-    , RequestHeaders-      -- ** Response header names-    , ResponseHeader-    , ResponseHeaders-      -- ** Response status code-    , Status (..)-    , status200, statusOK-    , status201, statusCreated-    , status206, statusPartialContent-    , status301, statusMovedPermanently-    , status302, statusFound-    , status303, statusSeeOther-    , status400, statusBadRequest-    , status401, statusUnauthorized-    , status403, statusForbidden-    , status404, statusNotFound-    , status405, statusNotAllowed-    , status500, statusServerError-      -- * WAI interface-    , Request (..)+    ( -- * WAI interface+      Request (..)     , Response (..)     , ResponseEnumerator     , responseEnumerator     , Application     , Middleware+    , FilePart (..)       -- * Response body smart constructors     , responseLBS     ) where  import qualified Data.ByteString as B-import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Lazy as L-import Data.Char (toLower)-import Data.String (IsString (..)) import Data.Typeable (Typeable)-import Data.Enumerator (Iteratee, ($$), joinI, run_)+import Data.Enumerator (Enumerator, Iteratee (..), ($$), joinI, run_) import qualified Data.Enumerator as E-import Data.Enumerator.IO (enumFile)+import qualified Data.Enumerator.List as EL+import Data.Enumerator.Binary (enumFile, enumFileRange) import Blaze.ByteString.Builder (Builder, fromByteString, fromLazyByteString)-import Data.Data (Data) import Network.Socket (SockAddr)---- | HTTP request method. Since the HTTP protocol allows arbitrary request--- methods, we leave this open as a 'B.ByteString'. Please note the request--- methods are case-sensitive.-type Method = B.ByteString---- | Version of HTTP protocol used in current request. The value given here--- should be everything following the \"HTTP/\" line in a request. In other--- words, HTTP\/1.1 -> \"1.1\", HTTP\/1.0 -> \"1.0\".-type HttpVersion = B.ByteString---- | HTTP/0.9-http09 :: HttpVersion-http09 = B8.pack "0.9"---- | HTTP/1.0-http10 :: HttpVersion-http10 = B8.pack "1.0"---- | HTTP/1.1-http11 :: HttpVersion-http11 = B8.pack "1.1"---- | A case insensitive bytestring, where the 'Eq' and 'Ord' instances do--- comparisons based on the lower-cased version of this string. For efficiency,--- this datatype contains both the original and lower-case version of the--- string; this means there is no need to lower-case the bytestring for every--- comparison.------ Please note that this datatype has an 'IsString' instance, which can allow--- for very concise code when using the OverloadedStrings language extension.-data CIByteString = CIByteString-    { ciOriginal :: !B.ByteString-    , ciLowerCase :: !B.ByteString-    }-    deriving (Data, Typeable)---- | Convert a regular bytestring to a case-insensitive bytestring.-mkCIByteString :: B.ByteString -> CIByteString-mkCIByteString bs = CIByteString bs $ B8.map toLower bs--instance Show CIByteString where-    show = show . ciOriginal-instance Read CIByteString where-    readsPrec i = map (\(x, y) -> (mkCIByteString x, y)) . readsPrec i-instance Eq CIByteString where-    x == y = ciLowerCase x == ciLowerCase y-instance Ord CIByteString where-    x <= y = ciLowerCase x <= ciLowerCase y-instance IsString CIByteString where-    fromString = mkCIByteString . fromString---- | Headers sent from the client to the server. Note that this is a--- case-insensitive string, as the HTTP spec specifies.-type RequestHeader = CIByteString-type RequestHeaders = [(RequestHeader, B.ByteString)]---- | Headers sent from the server to the client. Note that this is a--- case-insensitive string, as the HTTP spec specifies.-type ResponseHeader = CIByteString-type ResponseHeaders = [(ResponseHeader, B.ByteString)]---- | HTTP status code; a combination of the integral code and a status message.--- Equality is determined solely on the basis of the integral code.-data Status = Status { statusCode :: Int, statusMessage :: B.ByteString }-    deriving Show--instance Eq Status where-    x == y = statusCode x == statusCode y---- | OK-status200, statusOK :: Status-status200 = Status 200 $ B8.pack "OK"-statusOK = status200---- | Created-status201, statusCreated :: Status-status201 = Status 201 $ B8.pack "Created"-statusCreated = status201---- | Partial Content-status206, statusPartialContent :: Status-status206 = Status 206 $ B8.pack "Partial Content"-statusPartialContent = status206---- | Moved Permanently-status301, statusMovedPermanently :: Status-status301 = Status 301 $ B8.pack "Moved Permanently"-statusMovedPermanently = status301---- | Found-status302, statusFound :: Status-status302 = Status 302 $ B8.pack "Found"-statusFound = status302---- | See Other-status303, statusSeeOther :: Status-status303 = Status 303 $ B8.pack "See Other"-statusSeeOther = status303---- | Bad Request-status400, statusBadRequest :: Status-status400 = Status 400 $ B8.pack "Bad Request"-statusBadRequest = status400---- | Unauthorized-status401, statusUnauthorized :: Status-status401 = Status 401 $ B8.pack "Unauthorized"-statusUnauthorized = status401---- | Forbidden-status403, statusForbidden :: Status-status403 = Status 403 $ B8.pack "Forbidden"-statusForbidden = status403---- | Not Found-status404, statusNotFound :: Status-status404 = Status 404 $ B8.pack "Not Found"-statusNotFound = status404---- | Method Not Allowed-status405, statusNotAllowed :: Status-status405 = Status 405 $ B8.pack "Method Not Allowed"-statusNotAllowed = status405---- | Internal Server Error-status500, statusServerError :: Status-status500 = Status 500 $ B8.pack "Internal Server Error"-statusServerError = status500+import qualified Network.HTTP.Types as H+import Data.Text (Text)+import Data.ByteString.Lazy.Char8 () -- makes it easier to use responseLBS  -- | Information on the request sent by the client. This abstracts away the -- details of the underlying implementation. data Request = Request-  {  requestMethod  :: Method-  ,  httpVersion    :: HttpVersion+  {  requestMethod  :: H.Method+  ,  httpVersion    :: H.HttpVersion   -- | Extra path information sent by the client. The meaning varies slightly   -- depending on backend; in a standalone server setting, this is most likely   -- all information after the domain name. In a CGI application, this would be   -- the information following the path to the CGI executable itself.-  ,  pathInfo       :: B.ByteString-  -- | If no query string was specified, this should be empty.-  ,  queryString    :: B.ByteString+  ,  rawPathInfo    :: B.ByteString+  -- | If no query string was specified, this should be empty. This value+  -- /will/ include the leading question mark.+  ,  rawQueryString :: B.ByteString+  -- | Generally the host requested by the user via the Host request header.+  -- Backends are free to provide alternative values as necessary. This value+  -- should not be used to construct URLs.   ,  serverName     :: B.ByteString+  -- | The listening port that the server received this request on. It is+  -- possible for a server to listen on a non-numeric port (i.e., Unix named+  -- socket), in which case this value will be arbitrary. Like 'serverName',+  -- this value should not be used in URL construction.   ,  serverPort     :: Int-  ,  requestHeaders :: [(RequestHeader, B.ByteString)]-  -- ^ Was this request made over an SSL connection?+  ,  requestHeaders :: H.RequestHeaders+  -- | Was this request made over an SSL connection?   ,  isSecure       :: Bool-  -- ^ Log the given line in some method; how this is accomplished is-  -- server-dependant.-  ,  errorHandler   :: String -> IO ()   -- | The client\'s host information.   ,  remoteHost     :: SockAddr+  -- | Path info, broken down into individual components.+  ,  pathInfo       :: [Text]+  -- | Parsed query string information+  ,  queryString    :: H.Query   }   deriving Typeable  data Response-    = ResponseFile Status ResponseHeaders FilePath-    | ResponseBuilder Status ResponseHeaders Builder+    = ResponseFile H.Status H.ResponseHeaders FilePath (Maybe FilePart)+    | ResponseBuilder H.Status H.ResponseHeaders Builder     | ResponseEnumerator (forall a. ResponseEnumerator a)   deriving Typeable +data FilePart = FilePart+    { filePartOffset :: Integer+    , filePartByteCount :: Integer+    }+ type ResponseEnumerator a =-    (Status -> ResponseHeaders -> Iteratee Builder IO a) -> IO a+    (H.Status -> H.ResponseHeaders -> Iteratee Builder IO a) -> IO a  responseEnumerator :: Response -> ResponseEnumerator a responseEnumerator (ResponseEnumerator e) f = e f-responseEnumerator (ResponseFile s h fp) f =-    run_ $ enumFile fp $$ joinI $ E.map fromByteString $$ f s h+responseEnumerator (ResponseFile s h fp mpart) f =+    run_ $ (maybe enumFile enumFilePart) mpart fp $$ joinI+         $ EL.map fromByteString $$ f s h responseEnumerator (ResponseBuilder s h b) f = run_ $ do     E.yield () $ E.Chunks [b]     f s h -responseLBS :: Status -> ResponseHeaders -> L.ByteString -> Response+enumFilePart :: FilePart -> FilePath -> Enumerator B.ByteString IO a+enumFilePart (FilePart offset count) fp =+    enumFileRange fp (Just offset) (Just count)++responseLBS :: H.Status -> H.ResponseHeaders -> L.ByteString -> Response responseLBS s h = ResponseBuilder s h . fromLazyByteString  type Application = Request -> Iteratee B.ByteString IO Response
wai.cabal view
@@ -1,5 +1,5 @@ Name:                wai-Version:             0.3.2+Version:             0.4.0 Synopsis:            Web Application Interface. Description:         Provides a common protocol for communication between web aplications and web servers. License:             BSD3@@ -19,8 +19,11 @@ Library   Build-Depends:     base                   >= 3        && < 5                    , bytestring             >= 0.9      && < 0.10-                   , blaze-builder          >= 0.2      && < 0.3-                   , enumerator             >= 0.4      && < 0.5+                   , blaze-builder          >= 0.2      && < 0.4+                   , enumerator             >= 0.4.8    && < 0.5                    , network                >= 2.2      && < 2.4+                   , http-types             >= 0.6      && < 0.7+                   , text                   >= 0.5      && < 1.0+                   , transformers           >= 0.2      && < 0.3   Exposed-modules:   Network.Wai   ghc-options:       -Wall