@@ -1,10 +1,11 @@
11{-# LANGUAGE OverloadedStrings #-}
22{-# LANGUAGE RankNTypes #-}
3+-- | Backend for Common Gateway Interface. Almost all users should use the
4+-- 'run' function.
35module Network.Wai.Handler.CGI
46 ( run
5− , run'
6− , run''
77 , runSendfile
8+ , runGeneric
89 , requestBodyFunc
910 ) where
1011
@@ -42,38 +43,36 @@ safeRead d s =
4243lookup' :: String -> [(String, String)] -> String
4344lookup' key pairs = fromMaybe "" $ lookup key pairs
4445
46+-- | Run an application using CGI.
4547run :: Application -> IO ()
4648run app = do
4749 vars <- getEnvironment
4850 let input = requestBodyHandle System.IO.stdin
4951 output = B.hPut System.IO.stdout
50− run'' vars input output Nothing app
52+ runGeneric vars input output Nothing app
5153
54+-- | Some web servers provide an optimization for sending files via a sendfile
55+-- system call via a special header. To use this feature, provide that header
56+-- name here.
5257runSendfile :: B.ByteString -- ^ sendfile header
5358 -> Application -> IO ()
5459runSendfile sf app = do
5560 vars <- getEnvironment
5661 let input = requestBodyHandle System.IO.stdin
5762 output = B.hPut System.IO.stdout
58− run'' vars input output (Just sf) app
63+ runGeneric vars input output (Just sf) app
5964
60−run' :: [(String, String)] -- ^ all variables
61− -> System.IO.Handle -- ^ responseBody of input
62− -> System.IO.Handle -- ^ destination for output
63− -> Application
64− -> IO ()
65−run' vars inputH outputH app = do
66− let input = requestBodyHandle inputH
67− output = B.hPut outputH
68− run'' vars input output Nothing app
69−
70−run'' :: [(String, String)] -- ^ all variables
65+-- | A generic CGI helper, which allows other backends (FastCGI and SCGI) to
66+-- use the same code as CGI. Most users will not need this function, and can
67+-- stick with 'run' or 'runSendfile'.
68+runGeneric
69+ :: [(String, String)] -- ^ all variables
7170 -> (forall a. Int -> Enumerator B.ByteString IO a) -- ^ responseBody of input
7271 -> (B.ByteString -> IO ()) -- ^ destination for output
7372 -> Maybe B.ByteString -- ^ does the server support the X-Sendfile header?
7473 -> Application
7574 -> IO ()
76−run'' vars inputH outputH xsendfile app = do
75+runGeneric vars inputH outputH xsendfile app = do
7776 let rmethod = B.pack $ lookup' "REQUEST_METHOD" vars
7877 pinfo = lookup' "PATH_INFO" vars
7978 qstring = lookup' "QUERY_STRING" vars