on master help sign in
Response a
commit47f1ebee6472560aa6062dea000778eb802a743d authorMichael Snoyman <michael@snoyman.com> dateWed 15 Dec 2010, 19:00 (16 years ago) parentdfe4cdc
5 files changed+37−35
Network/Wai/Handler/CGI.hs+4−4 Network/Wai/Handler/SimpleServer.hs+4−4 Network/Wai/Middleware/CleanPath.hs+2−2 Network/Wai/Middleware/Gzip.hs+24−22 Network/Wai/Middleware/Jsonp.hs+3−3
Network/Wai/Handler/CGI.hs+4−4
@@ -27,7 +27,7 @@ safeRead d s =
2727lookup' :: String -> [(String, String)] -> String
2828lookup' key pairs = fromMaybe "" $ lookup key pairs
2929
30−run :: Application -> IO ()
30+run :: Application () -> IO ()
3131run app = do
3232 vars <- getEnvironment
3333 let input = requestBodyHandle System.IO.stdin
@@ -35,7 +35,7 @@ run app = do
3535 run'' vars input output Nothing app
3636
3737runSendfile :: String -- ^ sendfile header
38− -> Application -> IO ()
38+ -> Application () -> IO ()
3939runSendfile sf app = do
4040 vars <- getEnvironment
4141 let input = requestBodyHandle System.IO.stdin
@@ -45,7 +45,7 @@ runSendfile sf app = do
4545run' :: [(String, String)] -- ^ all variables
4646 -> System.IO.Handle -- ^ responseBody of input
4747 -> System.IO.Handle -- ^ destination for output
48− -> Application
48+ -> Application ()
4949 -> IO ()
5050run' vars inputH outputH app = do
5151 let input = requestBodyHandle inputH
@@ -56,7 +56,7 @@ run'' :: [(String, String)] -- ^ all variables
5656 -> (forall a. Int -> Enumerator B.ByteString IO a) -- ^ responseBody of input
5757 -> (B.ByteString -> IO ()) -- ^ destination for output
5858 -> Maybe String -- ^ does the server support the X-Sendfile header?
59− -> Application
59+ -> Application ()
6060 -> IO ()
6161run'' vars inputH outputH xsendfile app = do
6262 let rmethod = B.pack $ lookup' "REQUEST_METHOD" vars
Network/Wai/Handler/SimpleServer.hs+4−4
@@ -51,7 +51,7 @@ import Blaze.ByteString.Builder (fromByteString, Builder, toLazyByteString)
5151import Blaze.ByteString.Builder.Char8 (fromChar)
5252import Data.Monoid (mconcat)
5353
54−run :: Port -> Application -> IO ()
54+run :: Port -> Application () -> IO ()
5555run port = withSocketsDo .
5656 bracket
5757 (listenOn $ PortNumber $ fromIntegral port)
@@ -59,13 +59,13 @@ run port = withSocketsDo .
5959 serveConnections port
6060type Port = Int
6161
62−serveConnections :: Port -> Application -> Socket -> IO ()
62+serveConnections :: Port -> Application () -> Socket -> IO ()
6363serveConnections port app socket = do
6464 (conn, remoteHost', _) <- accept socket
6565 _ <- forkIO $ serveConnection port app conn remoteHost'
6666 serveConnections port app socket
6767
68−serveConnection :: Port -> Application -> Handle -> String -> IO ()
68+serveConnection :: Port -> Application () -> Handle -> String -> IO ()
6969serveConnection port app conn remoteHost' =
7070 finally
7171 serveConnection'
@@ -176,7 +176,7 @@ headers httpversion status responseHeaders = mconcat
176176 , fromByteString "\r\n"
177177 ]
178178
179−sendResponse :: HttpVersion -> Handle -> Response -> IO ()
179+sendResponse :: HttpVersion -> Handle -> Response () -> IO ()
180180sendResponse hv handle res = do
181181 responseEnumerator res $ \s hs -> do
182182 liftIO $ L.hPutStr handle $ toLazyByteString $ headers hv s hs
Network/Wai/Middleware/CleanPath.hs+2−2
@@ -9,9 +9,9 @@ import qualified Data.ByteString.Lazy as L
99
1010cleanPath :: (B.ByteString -> Either B.ByteString [String])
1111 -> B.ByteString
12− -> ([String] -> Request -> IO Response)
12+ -> ([String] -> Request -> IO (Response a))
1313 -> Request
14− -> IO Response
14+ -> IO (Response a)
1515cleanPath splitter prefix app env =
1616 case splitter $ pathInfo env of
1717 Right pieces -> app pieces env
Network/Wai/Middleware/Gzip.hs+24−22
@@ -30,29 +30,31 @@ import qualified Data.ByteString.Char8 as B
3030--
3131-- * Only compress if the response is above a certain size.
3232--
33−-- * Add Content-Length.
34−--
35−-- * I read somewhere that \"the beast\" (MSIE) can\'t support compression
36−-- for Javascript files..
37−gzip :: Middleware
38−gzip app env = do
33+-- * I've read that IE can\'t support compression for Javascript files.
34+gzip :: Bool -- ^ should we gzip files?
35+ -> Middleware a
36+gzip files app env = do
3937 res <- app env
40− case res of
41− ResponseFile{} -> return res
42− _ -> error "FIXME"
43− {-
44− let enc = fromMaybe []
45− $ (splitCommas . B.unpack)
46− `fmap` lookup "Accept-Encoding"
47− (requestHeaders env)
48− if "gzip" `elem` enc
49− then return res
50− { responseBody = compressE $ responseBody res
51− , responseHeaders = ("Content-Encoding", "gzip")
52− : responseHeaders res
53− }
54− else return res
55− -}
38+ case shouldGzip res of
39+ Nothing -> return res
40+ Just enum -> return $ ResponseEnumerator $ compressE enum
41+ where
42+ shouldGzip (ResponseFile _ hs _)
43+ | not files = Nothing
44+ shouldGzip res =
45+ if "gzip" `elem` enc
46+ then Just $ responseEnumerator res
47+ else Nothing
48+ enc = fromMaybe [] $ (splitCommas . B.unpack)
49+ `fmap` lookup "Accept-Encoding" (requestHeaders env)
50+
51+compressE :: ResponseEnumerator a -> ResponseEnumerator a
52+compressE re f =
53+ re f'
54+ --e s hs'
55+ where
56+ f' = undefined
57+ --hs' = ("Content-Encoding", "gzip") : hs
5658
5759{-
5860compressE :: ResponseBody -> ResponseBody
Network/Wai/Middleware/Jsonp.hs+3−3
@@ -40,7 +40,7 @@ dropQM bs
4040-- \"application/json\" response, then convern that into a JSONP response,
4141-- having a content type of \"text\/javascript\" and calling the specified
4242-- callback function.
43−jsonp :: Middleware
43+jsonp :: Middleware a
4444jsonp app env = do
4545 let accept = fromMaybe B8.empty $ lookup "Accept" $ requestHeaders env
4646 let callback :: Maybe B8.ByteString
@@ -75,8 +75,8 @@ jsonp app env = do
7575 Nothing -> Nothing
7676 fixHeaders = changeVal "Content-Type" "text/javascript"
7777
78−enumResponse :: Response -> ResponseEnumerator a
79−enumResponse = undefined
78+enumResponse :: Response a -> ResponseEnumerator a
79+enumResponse = error "FIXME"
8080
8181{-
8282addCallback :: B8.ByteString -> Enumerator -> Enumerator