on master help sign in
Removed type variable on Response et al
cc2aa61Michael Snoyman
Network/Wai/Handler/CGI.hs+4−4
@@ -36,7 +36,7 @@ safeRead d s =
36lookup' :: String -> [(String, String)] -> String
36lookup' :: String -> [(String, String)] -> String
37lookup' key pairs = fromMaybe "" $ lookup key pairs
37lookup' key pairs = fromMaybe "" $ lookup key pairs
38
38
39−run :: Application () -> IO ()
39+run :: Application -> IO ()
40run app = do
40run app = do
41 vars <- getEnvironment
41 vars <- getEnvironment
42 let input = requestBodyHandle System.IO.stdin
42 let input = requestBodyHandle System.IO.stdin
@@ -44,7 +44,7 @@ run app = do
44 run'' vars input output Nothing app
44 run'' vars input output Nothing app
45
45
46runSendfile :: B.ByteString -- ^ sendfile header
46runSendfile :: B.ByteString -- ^ sendfile header
47− -> Application () -> IO ()
47+ -> Application -> IO ()
48runSendfile sf app = do
48runSendfile sf app = do
49 vars <- getEnvironment
49 vars <- getEnvironment
50 let input = requestBodyHandle System.IO.stdin
50 let input = requestBodyHandle System.IO.stdin
@@ -54,7 +54,7 @@ runSendfile sf app = do
54run' :: [(String, String)] -- ^ all variables
54run' :: [(String, String)] -- ^ all variables
55 -> System.IO.Handle -- ^ responseBody of input
55 -> System.IO.Handle -- ^ responseBody of input
56 -> System.IO.Handle -- ^ destination for output
56 -> System.IO.Handle -- ^ destination for output
57− -> Application ()
57+ -> Application
58 -> IO ()
58 -> IO ()
59run' vars inputH outputH app = do
59run' vars inputH outputH app = do
60 let input = requestBodyHandle inputH
60 let input = requestBodyHandle inputH
@@ -65,7 +65,7 @@ run'' :: [(String, String)] -- ^ all variables
65 -> (forall a. Int -> Enumerator B.ByteString IO a) -- ^ responseBody of input
65 -> (forall a. Int -> Enumerator B.ByteString IO a) -- ^ responseBody of input
66 -> (B.ByteString -> IO ()) -- ^ destination for output FIXME use an iteratee
66 -> (B.ByteString -> IO ()) -- ^ destination for output FIXME use an iteratee
67 -> Maybe B.ByteString -- ^ does the server support the X-Sendfile header?
67 -> Maybe B.ByteString -- ^ does the server support the X-Sendfile header?
68− -> Application ()
68+ -> Application
69 -> IO ()
69 -> IO ()
70run'' vars inputH outputH xsendfile app = do
70run'' vars inputH outputH xsendfile app = do
71 let rmethod = B.pack $ lookup' "REQUEST_METHOD" vars
71 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)
49import Blaze.ByteString.Builder.Char8 (fromChar, fromString)
49import Blaze.ByteString.Builder.Char8 (fromChar, fromString)
50import Data.Monoid (mconcat)
50import Data.Monoid (mconcat)
51
51
52−run :: Port -> Application () -> IO ()
52+run :: Port -> Application -> IO ()
53run port = withSocketsDo .
53run port = withSocketsDo .
54 bracket
54 bracket
55 (listenOn $ PortNumber $ fromIntegral port)
55 (listenOn $ PortNumber $ fromIntegral port)
@@ -57,13 +57,13 @@ run port = withSocketsDo .
57 serveConnections port
57 serveConnections port
58type Port = Int
58type Port = Int
59
59
60−serveConnections :: Port -> Application () -> Socket -> IO ()
60+serveConnections :: Port -> Application -> Socket -> IO ()
61serveConnections port app socket = do
61serveConnections port app socket = do
62 (conn, remoteHost', _) <- accept socket
62 (conn, remoteHost', _) <- accept socket
63 _ <- forkIO $ serveConnection port app conn remoteHost'
63 _ <- forkIO $ serveConnection port app conn remoteHost'
64 serveConnections port app socket
64 serveConnections port app socket
65
65
66−serveConnection :: Port -> Application () -> Handle -> String -> IO ()
66+serveConnection :: Port -> Application -> Handle -> String -> IO ()
67serveConnection port app conn remoteHost' =
67serveConnection port app conn remoteHost' =
68 finally
68 finally
69 serveConnection'
69 serveConnection'
@@ -174,7 +174,7 @@ headers httpversion status responseHeaders = mconcat
174 , fromByteString "\r\n"
174 , fromByteString "\r\n"
175 ]
175 ]
176
176
177−sendResponse :: HttpVersion -> Handle -> Response () -> IO ()
177+sendResponse :: HttpVersion -> Handle -> Response -> IO ()
178sendResponse hv handle res = do
178sendResponse hv handle res = do
179 responseEnumerator res $ \s hs ->
179 responseEnumerator res $ \s hs ->
180 enumList 1 [headers hv s hs]
180 enumList 1 [headers hv s hs]
Network/Wai/Middleware/CleanPath.hs+2−2
@@ -9,9 +9,9 @@ import qualified Data.ByteString.Lazy as L
9
9
10cleanPath :: (B.ByteString -> Either B.ByteString [String])
10cleanPath :: (B.ByteString -> Either B.ByteString [String])
11 -> B.ByteString
11 -> B.ByteString
12− -> ([String] -> Request -> IO (Response a))
12+ -> ([String] -> Request -> IO Response)
13 -> Request
13 -> Request
14− -> IO (Response a)
14+ -> IO Response
15cleanPath splitter prefix app env =
15cleanPath splitter prefix app env =
16 case splitter $ pathInfo env of
16 case splitter $ pathInfo env of
17 Right pieces -> app pieces env
17 Right pieces -> app pieces env
Network/Wai/Middleware/Gzip.hs+9−10
@@ -33,22 +33,21 @@ import Data.Enumerator (($$), joinI)
33--
33--
34-- * I've read that IE can\'t support compression for Javascript files.
34-- * I've read that IE can\'t support compression for Javascript files.
35gzip :: Bool -- ^ should we gzip files?
35gzip :: Bool -- ^ should we gzip files?
36− -> Middleware a
36+ -> Middleware
37gzip files app env = do
37gzip files app env = do
38 res <- app env
38 res <- app env
39+ return $
39− case shouldGzip res of
40+ case res of
40− Nothing -> return res
41+ ResponseFile{} | not files -> res
42+ _ -> if "gzip" `elem` enc
41− Just enum -> return $ ResponseEnumerator $ compressE enum
43+ then ResponseEnumerator $ compressE $ responseEnumerator res
44+ else res
42 where
45 where
43− shouldGzip ResponseFile{} | 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)
46 enc = fromMaybe [] $ (splitCommas . B.unpack)
49 `fmap` lookup "Accept-Encoding" (requestHeaders env)
47 `fmap` lookup "Accept-Encoding" (requestHeaders env)
50
48
51−compressE :: ResponseEnumerator a -> ResponseEnumerator a
49+compressE :: (forall a. ResponseEnumerator a)
50+ -> (forall a. ResponseEnumerator a)
52compressE re f =
51compressE re f =
53 re f'
52 re f'
54 --e s hs'
53 --e s hs'
Network/Wai/Middleware/Jsonp.hs+3−2
@@ -1,4 +1,5 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE RankNTypes #-}
2---------------------------------------------------------
3---------------------------------------------------------
3-- |
4-- |
4-- Module : Network.Wai.Middleware.Jsonp
5-- Module : Network.Wai.Middleware.Jsonp
@@ -43,7 +44,7 @@ dropQM bs
43-- \"application/json\" response, then convern that into a JSONP response,
44-- \"application/json\" response, then convern that into a JSONP response,
44-- having a content type of \"text\/javascript\" and calling the specified
45-- having a content type of \"text\/javascript\" and calling the specified
45-- callback function.
46-- callback function.
46−jsonp :: Middleware a
47+jsonp :: Middleware
47jsonp app env = do
48jsonp app env = do
48 let accept = fromMaybe B8.empty $ lookup "Accept" $ requestHeaders env
49 let accept = fromMaybe B8.empty $ lookup "Accept" $ requestHeaders env
49 let callback :: Maybe B8.ByteString
50 let callback :: Maybe B8.ByteString
@@ -76,7 +77,7 @@ jsonp app env = do
76 Just "application/json" -> Just $ fixHeaders hs
77 Just "application/json" -> Just $ fixHeaders hs
77 _ -> Nothing
78 _ -> Nothing
78 fixHeaders = changeVal "Content-Type" "text/javascript"
79 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
80 addCallback cb e =
81 addCallback cb e =
81 return $ ResponseEnumerator $ helper
82 return $ ResponseEnumerator $ helper
82 where
83 where
Network/Wai/Zlib.hs+9−36
@@ -1,10 +1,8 @@
1module Network.Wai.Zlib (compress) where
1module Network.Wai.Zlib (compress) where
2
2
3import Prelude hiding (head)
3import Prelude hiding (head)
4−import Network.Wai
5−import Data.ByteString (ByteString)
6import Data.Enumerator
4import Data.Enumerator
7− ( Enumeratee, checkDone, Stream (..), continue
5+ ( Enumeratee, checkDone, Stream (..)
8 , (>>==), head, ($$), joinI
6 , (>>==), head, ($$), joinI
9 )
7 )
10import Blaze.ByteString.Builder (Builder, fromByteString)
8import Blaze.ByteString.Builder (Builder, fromByteString)
@@ -32,36 +30,11 @@ compress step0 = joinI $ builderToByteString $$ do
32 case bss of
30 case bss of
33 [] -> step def k
31 [] -> step def k
34 _ -> k (Chunks bss) >>== loop def
32 _ -> k (Chunks bss) >>== loop def
35−
36−drain =
33+ drain =
37− go id
34+ go id
38− where
35+ where
39− go front mbs' = do
36+ go front mbs' = do
40− mbs <- mbs'
37+ mbs <- mbs'
41− case mbs of
38+ case mbs of
42− Nothing -> return $ map fromByteString $ front []
39+ Nothing -> return $ map fromByteString $ front []
43− Just bs -> go (front . (:) bs) mbs'
40+ 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− -}