on master help sign in
Removed type variable on Response et al
commitcc2aa619ebbfce18947d5f873b3e0b94e21fcc6f authorMichael Snoyman <michael@snoyman.com> dateThu 16 Dec 2010, 20:28 (16 years ago) parent697185e
6 files changed+31−58
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+9−10 Network/Wai/Middleware/Jsonp.hs+3−2 Network/Wai/Zlib.hs+9−36
Network/Wai/Handler/CGI.hs+4−4
@@ -36,7 +36,7 @@ safeRead d s =
3636lookup' :: String -> [(String, String)] -> String
3737lookup' key pairs = fromMaybe "" $ lookup key pairs
3838
39−run :: Application () -> IO ()
39+run :: Application -> IO ()
4040run app = do
4141 vars <- getEnvironment
4242 let input = requestBodyHandle System.IO.stdin
@@ -44,7 +44,7 @@ run app = do
4444 run'' vars input output Nothing app
4545
4646runSendfile :: B.ByteString -- ^ sendfile header
47− -> Application () -> IO ()
47+ -> Application -> IO ()
4848runSendfile sf app = do
4949 vars <- getEnvironment
5050 let input = requestBodyHandle System.IO.stdin
@@ -54,7 +54,7 @@ runSendfile sf app = do
5454run' :: [(String, String)] -- ^ all variables
5555 -> System.IO.Handle -- ^ responseBody of input
5656 -> System.IO.Handle -- ^ destination for output
57− -> Application ()
57+ -> Application
5858 -> IO ()
5959run' vars inputH outputH app = do
6060 let input = requestBodyHandle inputH
@@ -65,7 +65,7 @@ run'' :: [(String, String)] -- ^ all variables
6565 -> (forall a. Int -> Enumerator B.ByteString IO a) -- ^ responseBody of input
6666 -> (B.ByteString -> IO ()) -- ^ destination for output FIXME use an iteratee
6767 -> Maybe B.ByteString -- ^ does the server support the X-Sendfile header?
68− -> Application ()
68+ -> Application
6969 -> IO ()
7070run'' vars inputH outputH xsendfile app = do
7171 let rmethod = B.pack $ lookup' "REQUEST_METHOD" vars
Network/Wai/Handler/SimpleServer.hs+4−4
@@ -49,7 +49,7 @@ import Blaze.ByteString.Builder (fromByteString, Builder)
4949import Blaze.ByteString.Builder.Char8 (fromChar, fromString)
5050import Data.Monoid (mconcat)
5151
52−run :: Port -> Application () -> IO ()
52+run :: Port -> Application -> IO ()
5353run port = withSocketsDo .
5454 bracket
5555 (listenOn $ PortNumber $ fromIntegral port)
@@ -57,13 +57,13 @@ run port = withSocketsDo .
5757 serveConnections port
5858type Port = Int
5959
60−serveConnections :: Port -> Application () -> Socket -> IO ()
60+serveConnections :: Port -> Application -> Socket -> IO ()
6161serveConnections port app socket = do
6262 (conn, remoteHost', _) <- accept socket
6363 _ <- forkIO $ serveConnection port app conn remoteHost'
6464 serveConnections port app socket
6565
66−serveConnection :: Port -> Application () -> Handle -> String -> IO ()
66+serveConnection :: Port -> Application -> Handle -> String -> IO ()
6767serveConnection port app conn remoteHost' =
6868 finally
6969 serveConnection'
@@ -174,7 +174,7 @@ headers httpversion status responseHeaders = mconcat
174174 , fromByteString "\r\n"
175175 ]
176176
177−sendResponse :: HttpVersion -> Handle -> Response () -> IO ()
177+sendResponse :: HttpVersion -> Handle -> Response -> IO ()
178178sendResponse hv handle res = do
179179 responseEnumerator res $ \s hs ->
180180 enumList 1 [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 a))
12+ -> ([String] -> Request -> IO Response)
1313 -> Request
14− -> IO (Response a)
14+ -> IO Response
1515cleanPath splitter prefix app env =
1616 case splitter $ pathInfo env of
1717 Right pieces -> app pieces env
Network/Wai/Middleware/Gzip.hs+9−10
@@ -33,22 +33,21 @@ import Data.Enumerator (($$), joinI)
3333--
3434-- * I've read that IE can\'t support compression for Javascript files.
3535gzip :: Bool -- ^ should we gzip files?
36− -> Middleware a
36+ -> Middleware
3737gzip files app env = do
3838 res <- app env
39− case shouldGzip res of
40− Nothing -> return res
41− Just enum -> return $ ResponseEnumerator $ compressE enum
39+ return $
40+ case res of
41+ ResponseFile{} | not files -> res
42+ _ -> if "gzip" `elem` enc
43+ then ResponseEnumerator $ compressE $ responseEnumerator res
44+ else res
4245 where
43− shouldGzip ResponseFile{} | not files = Nothing
44− shouldGzip res =
45− if "gzip" `elem` enc
46− then Just $ responseEnumerator res
47− else Nothing
4846 enc = fromMaybe [] $ (splitCommas . B.unpack)
4947 `fmap` lookup "Accept-Encoding" (requestHeaders env)
5048
51−compressE :: ResponseEnumerator a -> ResponseEnumerator a
49+compressE :: (forall a. ResponseEnumerator a)
50+ -> (forall a. ResponseEnumerator a)
5251compressE re f =
5352 re f'
5453 --e s hs'
Network/Wai/Middleware/Jsonp.hs+3−2
@@ -1,4 +1,5 @@
11{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE RankNTypes #-}
23---------------------------------------------------------
34-- |
45-- Module : Network.Wai.Middleware.Jsonp
@@ -43,7 +44,7 @@ dropQM bs
4344-- \"application/json\" response, then convern that into a JSONP response,
4445-- having a content type of \"text\/javascript\" and calling the specified
4546-- callback function.
46−jsonp :: Middleware a
47+jsonp :: Middleware
4748jsonp app env = do
4849 let accept = fromMaybe B8.empty $ lookup "Accept" $ requestHeaders env
4950 let callback :: Maybe B8.ByteString
@@ -76,7 +77,7 @@ jsonp app env = do
7677 Just "application/json" -> Just $ fixHeaders hs
7778 _ -> Nothing
7879 fixHeaders = changeVal "Content-Type" "text/javascript"
79− addCallback :: B8.ByteString -> ResponseEnumerator a -> IO (Response a)
80+ addCallback :: B8.ByteString -> (forall a. ResponseEnumerator a) -> IO Response
8081 addCallback cb e =
8182 return $ ResponseEnumerator $ helper
8283 where
Network/Wai/Zlib.hs+9−36
@@ -1,10 +1,8 @@
11module Network.Wai.Zlib (compress) where
22
33import Prelude hiding (head)
4−import Network.Wai
5−import Data.ByteString (ByteString)
64import Data.Enumerator
7− ( Enumeratee, checkDone, Stream (..), continue
5+ ( Enumeratee, checkDone, Stream (..)
86 , (>>==), head, ($$), joinI
97 )
108import Blaze.ByteString.Builder (Builder, fromByteString)
@@ -32,36 +30,11 @@ compress step0 = joinI $ builderToByteString $$ do
3230 case bss of
3331 [] -> step def k
3432 _ -> k (Chunks bss) >>== loop def
35−
36−drain =
37− go id
38− where
39− go front mbs' = do
40− mbs <- mbs'
41− case mbs of
42− Nothing -> return $ map fromByteString $ front []
43− Just bs -> go (front . (:) bs) mbs'
44−
45− {-
46−
47−compressIter :: (acc -> ByteString -> IO (Either acc acc))
48− -> Deflate
49− -> acc
50− -> ByteString
51− -> IO (Either acc acc)
52−compressIter iter def acc bsI = withDeflateInput def bsI $ drain iter acc
53−
54−drain :: (acc -> ByteString -> IO (Either acc acc))
55− -> acc
56− -> IO (Maybe ByteString)
57− -> IO (Either acc acc)
58−drain iter acc pop = do
59− mbs <- pop
60− case mbs of
61− Nothing -> return $ Right acc
62− Just bs -> do
63− eacc' <- iter acc bs
64− case eacc' of
65− Left acc' -> return $ Left acc'
66− Right acc' -> drain iter acc' pop
67− -}
33+ drain =
34+ go id
35+ where
36+ go front mbs' = do
37+ mbs <- mbs'
38+ case mbs of
39+ Nothing -> return $ map fromByteString $ front []
40+ Just bs -> go (front . (:) bs) mbs'