packages feed

wai-extra 0.2.2.2 → 0.2.3

raw patch · 2 files changed

+27/−19 lines, 2 filesdep −sendfiledep ~directory

Dependencies removed: sendfile

Dependency ranges changed: directory

Files

Network/Wai/Handler/SimpleServer.hs view
@@ -16,6 +16,8 @@ --------------------------------------------------------- module Network.Wai.Handler.SimpleServer     ( run+    , sendResponse+    , parseRequest     ) where  import Network.Wai@@ -36,8 +38,8 @@  import Data.Typeable (Typeable) -import Network.Socket.SendFile import Control.Arrow (first)+import Numeric (showHex)  run :: Port -> Application -> IO () run port = withSocketsDo .@@ -60,14 +62,14 @@         (hClose conn)     where         serveConnection' = do-            env <- hParseRequest port conn remoteHost'+            env <- parseRequest port conn remoteHost'             res <- app env             sendResponse (httpVersion env) conn res -hParseRequest :: Port -> Handle -> String -> IO Request-hParseRequest port conn remoteHost' = do+parseRequest :: Port -> Handle -> String -> IO Request+parseRequest port conn remoteHost' = do     headers' <- takeUntilBlank conn id-    parseRequest port headers' conn remoteHost'+    parseRequest' port headers' conn remoteHost'  takeUntilBlank :: Handle                -> ([ByteString] -> [ByteString])@@ -93,12 +95,12 @@ instance Exception InvalidRequest  -- | Parse a set of header lines and body into a 'Request'.-parseRequest :: Port-             -> [ByteString]-             -> Handle-             -> String-             -> IO Request-parseRequest port lines' handle remoteHost' = do+parseRequest' :: Port+              -> [ByteString]+              -> Handle+              -> String+              -> IO Request+parseRequest' port lines' handle remoteHost' = do     case lines' of         (_:_:_) -> return ()         _ -> throwIO $ NotEnoughLines $ map B.unpack lines'@@ -154,14 +156,21 @@     B.hPut h $ statusMessage $ status res     B.hPut h $ B.pack "\r\n"     mapM_ putHeader $ responseHeaders res-    B.hPut h $ B.pack "\r\n"+    B.hPut h $ B.pack "Transfer-Encoding: chunked\r\n\r\n"     case responseBody res of-        ResponseFile fp -> unsafeSendFile h fp-        ResponseEnumerator (Enumerator enum) -> enum myPut h >> return ()-        ResponseLBS lbs -> L.hPut h lbs+        ResponseFile fp -> do+            -- FIXME this is lazy I/O+            lbs <- L.readFile fp+            mapM_ myPut $ L.toChunks lbs+        ResponseEnumerator (Enumerator enum) ->+            enum (const myPut) h >> return ()+        ResponseLBS lbs -> mapM_ myPut $ L.toChunks lbs+    B.hPut h $ B.pack "0\r\n\r\n"     where-        myPut _ bs = do+        myPut bs = do+            B.hPut h $ B.pack $ showHex (B.length bs) " \r\n"             B.hPut h bs+            B.hPut h $ B.pack "\r\n"             return (Right h)         putHeader (x, y) = do             B.hPut h $ ciOriginal x
wai-extra.cabal view
@@ -1,5 +1,5 @@ Name:                wai-extra-Version:             0.2.2.2+Version:             0.2.3 Synopsis:            Provides some basic WAI handlers and middleware. Description:         The goal here is to provide common features without many dependencies. License:             BSD3@@ -21,9 +21,8 @@                      wai >= 0.2.0 && < 0.3,                      old-locale >= 1.0 && < 1.1,                      time >= 1.1.4 && < 1.3,-                     sendfile >= 0.6.1 && < 0.8,                      network >= 2.2.1.5 && < 2.3,-                     directory >= 1.0.1 && < 1.1,+                     directory >= 1.0.1 && < 1.2,                      utf8-string >= 0.3.4 && < 0.4   Exposed-modules:   Network.Wai.Handler.CGI                      Network.Wai.Handler.SimpleServer