packages feed

wai-app-file-cgi 0.3.1 → 0.3.2

raw patch · 8 files changed

+21/−89 lines, 8 filesdep +wai-loggerdep −byteorderdep ~wai-app-static

Dependencies added: wai-logger

Dependencies removed: byteorder

Dependency ranges changed: wai-app-static

Files

Network/Wai/Application/Classic.hs view
@@ -5,20 +5,13 @@ module Network.Wai.Application.Classic (   -- * Types     AppSpec(..)-  , Logger   , FileInfo(..)   -- * Files   , FileRoute(..), fileApp   -- * CGI   , CgiRoute(..), cgiApp-  -- * Utilities for logging-  , NumericAddress, showSockAddr-  , FieldKey-  , lookupRequestField, lookupRequestField'   ) where  import Network.Wai.Application.Classic.CGI import Network.Wai.Application.Classic.File import Network.Wai.Application.Classic.Types-import Network.Wai.Application.Classic.Utils-import Network.Wai.Application.Classic.Header
Network/Wai/Application/Classic/CGI.hs view
@@ -22,6 +22,7 @@ import Network.Wai.Application.Classic.Header import Network.Wai.Application.Classic.Types import Network.Wai.Application.Classic.Utils+import Network.Wai.Logger.Utils import System.IO import System.Process @@ -85,7 +86,7 @@     toBuilder = EL.map fromByteString     emptyBody = EB.isolate 0     response build status hs = toBuilder =$ build status hs-    check hs = lookupField fkContentType hs >> case lookupField "status" hs of+    check hs = lookup fkContentType hs >> case lookup "status" hs of         Nothing -> Just (status200, hs)         Just l  -> toStatus l >>= \s -> Just (s,hs')       where@@ -111,9 +112,9 @@       , ("QUERY_STRING",      query req)       ]     headers = requestHeaders req-    addLength = addEnv "CONTENT_LENGTH" $ lookupField fkContentLength headers-    addType   = addEnv "CONTENT_TYPE" $ lookupField fkContentType headers-    addCookie = addEnv "HTTP_COOKIE" $ lookupField fkCookie headers+    addLength = addEnv "CONTENT_LENGTH" $ lookup fkContentLength headers+    addType   = addEnv "CONTENT_TYPE" $ lookup fkContentType headers+    addCookie = addEnv "HTTP_COOKIE" $ lookup fkCookie headers     query = BS.unpack . safeTail . rawQueryString       where         safeTail "" = ""
Network/Wai/Application/Classic/Field.hs view
@@ -20,7 +20,7 @@  ---------------------------------------------------------------- -languages :: Request -> [ByteString]+languages :: Request -> [Ascii] languages req = maybe [] parseLang $ lookupRequestField fkAcceptLanguage req  ifModifiedSince :: Request -> Maybe HTTPDate@@ -32,7 +32,7 @@ ifRange :: Request -> Maybe HTTPDate ifRange = lookupAndParseDate fkIfRange -lookupAndParseDate :: ByteString -> Request -> Maybe HTTPDate+lookupAndParseDate :: FieldKey -> Request -> Maybe HTTPDate lookupAndParseDate key req = lookupRequestField key req >>= parseHTTPDate  ----------------------------------------------------------------
Network/Wai/Application/Classic/Header.hs view
@@ -2,8 +2,6 @@  module Network.Wai.Application.Classic.Header where -import Data.ByteString (ByteString)-import Data.ByteString.Char8 () import Data.CaseInsensitive import Data.Maybe import Network.HTTP.Types@@ -12,10 +10,10 @@ ----------------------------------------------------------------  -- | Header field key. This must be lower case.-type FieldKey = ByteString+type FieldKey = CI Ascii  -- | A type for look-up key.-fkAcceptLanguage :: ByteString+fkAcceptLanguage :: FieldKey fkAcceptLanguage = "accept-language"  -- | Look-up key for Range:.@@ -63,25 +61,16 @@ {-|   Looking up a header in 'Request'. -}-lookupRequestField :: FieldKey -> Request -> Maybe ByteString-lookupRequestField x req = lookupField x hdrs+lookupRequestField :: FieldKey -> Request -> Maybe Ascii+lookupRequestField x req = lookup x hdrs   where     hdrs = requestHeaders req  {-|   Looking up a header in 'Request'. If the header does not exist,-  empty 'ByteString' is returned.+  empty 'Ascii' is returned. -}-lookupRequestField' :: FieldKey -> Request -> ByteString-lookupRequestField' x req = fromMaybe "" $ lookupField x hdrs+lookupRequestField' :: FieldKey -> Request -> Ascii+lookupRequestField' x req = fromMaybe "" $ lookup x hdrs   where     hdrs = requestHeaders req--{-|-  Looking up a header in 'RequestHeaders'.--}-lookupField :: FieldKey -> RequestHeaders -> Maybe ByteString-lookupField x ((key, val):kvs)-  | x == foldedCase key = Just val-  | otherwise           = lookupField x kvs-lookupField _ []        = Nothing
Network/Wai/Application/Classic/MaybeIter.hs view
@@ -39,7 +39,7 @@     case v of       Nothing -> nothing       Just x  -> act x-      + (|>|) :: MaybeIter a -> (a -> MaybeIter b) -> MaybeIter b a |>| act = do     v <- a
Network/Wai/Application/Classic/Types.hs view
@@ -4,7 +4,7 @@ import qualified Data.ByteString.Lazy as BL (ByteString) import Network.HTTP.Date import Network.HTTP.Types-import Network.Wai+import Network.Wai.Logger.Prefork  data AppSpec = AppSpec {     -- | Name specified to Server: in HTTP response.@@ -14,12 +14,10 @@     -- | Whether this is an HTML or not.   , isHTML :: ByteString -> Bool     -- | A function for logging. The third argument is a body size.-  , logger :: Logger+  , logger :: ApacheLogger     -- | A function to obtain information about a file.   , getFileInfo :: ByteString -> IO (Maybe FileInfo)   }--type Logger = Request -> Status -> Maybe Integer -> IO ()  data FileInfo = FileInfo {     fileInfoName :: FilePath
Network/Wai/Application/Classic/Utils.hs view
@@ -1,63 +1,14 @@ {-# LANGUAGE OverloadedStrings #-}  module Network.Wai.Application.Classic.Utils (-    NumericAddress, showSockAddr-  , hasTrailingPathSeparator, pathSep+    hasTrailingPathSeparator, pathSep   , (+++), (</>)   ) where -import Data.Bits import Data.ByteString (ByteString) import qualified Data.ByteString as BS import Data.ByteString.Char8 () import Data.Word-import Network.Socket (SockAddr(..))-import System.ByteOrder-import Text.Printf--{-|-  A type for IP address in numeric string representation.--}-type NumericAddress = String--showIPv4 :: Word32 -> Bool -> NumericAddress-showIPv4 w32 little-    | little    = show b1 ++ "." ++ show b2 ++ "." ++ show b3 ++ "." ++ show b4-    | otherwise = show b4 ++ "." ++ show b3 ++ "." ++ show b2 ++ "." ++ show b1-  where-    t1 = w32-    t2 = shift t1 (-8)-    t3 = shift t2 (-8)-    t4 = shift t3 (-8)-    b1 = t1 .&. 0x000000ff-    b2 = t2 .&. 0x000000ff-    b3 = t3 .&. 0x000000ff-    b4 = t4 .&. 0x000000ff--showIPv6 :: (Word32,Word32,Word32,Word32) -> String-showIPv6 (w1,w2,w3,w4) =-    printf "%x:%x:%x:%x:%x:%x:%x:%x" s1 s2 s3 s4 s5 s6 s7 s8-  where-    (s1,s2) = foo w1-    (s3,s4) = foo w2-    (s5,s6) = foo w3-    (s7,s8) = foo w4-    foo w = (h1,h2)-      where-        h1 = w .&. 0x0000ffff-        h2 = shift w (-16) .&. 0x0000ffff-{-|-  Convert 'SockAddr' to 'NumericAddress'. If the address is-  an IPv4-embedded IPv6 address, the IPv4 is extracted.--}--- HostAddr is network byte order.--- HostAddr6 is host byte order.-showSockAddr :: SockAddr -> NumericAddress-showSockAddr (SockAddrInet _ addr4)                       = showIPv4 addr4 (byteOrder == LittleEndian)-showSockAddr (SockAddrInet6 _ _ (0,0,0x0000ffff,addr4) _) = showIPv4 addr4 False-showSockAddr (SockAddrInet6 _ _ (0,0,0,1) _)              = "::1"-showSockAddr (SockAddrInet6 _ _ addr6 _)                  = showIPv6 addr6-showSockAddr _                                            = "unknownSocket"  pathSep :: Word8 pathSep = 47
wai-app-file-cgi.cabal view
@@ -1,5 +1,5 @@ Name:                   wai-app-file-cgi-Version:                0.3.1+Version:                0.3.2 Author:                 Kazu Yamamoto <kazu@iij.ad.jp> Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp> License:                BSD3@@ -34,8 +34,8 @@                         containers, attoparsec,                         wai, enumerator >= 0.4.9,                         bytestring, blaze-builder,-                        wai-app-static, http-types, http-date,-                        case-insensitive, static-hash, byteorder+                        wai-app-static >= 0.3, http-types, http-date,+                        case-insensitive, static-hash, wai-logger Source-Repository head   Type:                 git   Location:             git://github.com/kazu-yamamoto/wai-app-file-cgi.git