on master help sign in
X-Sendfile header support
commitd6110dd6a1e28fe885e06241201e2917edb5f3ec authorMichael Snoyman <michael@snoyman.com> dateTue 27 Jul 2010, 20:36 (16 years ago) parent244af9c
1 file changed+21−9
Network/Wai/Handler/FastCGI.hsc+21−9
Network/Wai/Handler/FastCGI.hsc+21−9
@@ -15,7 +15,10 @@
1515-- Totally ripped off by Michael Snoyman to work with Hack, then WAI.
1616--
1717-----------------------------------------------------------------------------
18−module Network.Wai.Handler.FastCGI (run) where
18+module Network.Wai.Handler.FastCGI
19+ ( run
20+ , runSendfile
21+ ) where
1922
2023import Data.Maybe
2124import Control.Monad ( liftM )
@@ -66,31 +69,39 @@ foreign import ccall unsafe "fcgiapp.h FCGX_Finish" fcgx_finish
6669
6770-- | Handle FastCGI requests in an infinite loop.
6871run :: W.Application -> IO ()
69−run f = runOneFastCGI f >> run f
72+run f = runOneFastCGI Nothing f >> run f
73+
74+-- | Handle FastCGI requests in an infinite loop. For a server which supports
75+-- the X-Sendfile header.
76+runSendfile :: String -> W.Application -> IO ()
77+runSendfile sf f = runOneFastCGI (Just sf) f >> runSendfile sf f
7078
7179-- | Handle a single FastCGI request.
72−runOneFastCGI :: W.Application -> IO ()
73−runOneFastCGI f = do
80+runOneFastCGI :: Maybe String -- X-Sendfile
81+ -> W.Application -> IO ()
82+runOneFastCGI xsendfile f = do
7483 alloca (\inp ->
7584 alloca (\outp ->
7685 alloca (\errp ->
7786 alloca (\envp ->
78− oneRequest f inp outp errp envp))))
87+ oneRequest f inp outp errp envp
88+ xsendfile))))
7989
8090oneRequest :: W.Application
8191 -> Ptr StreamPtr
8292 -> Ptr StreamPtr
8393 -> Ptr StreamPtr
8494 -> Ptr Environ
95+ -> Maybe String -- X-Sendfile
8596 -> IO ()
86−oneRequest f inp outp errp envp =
97+oneRequest f inp outp errp envp xsendfile =
8798 do
8899 testReturn "FCGX_Accept" $ fcgx_accept inp outp errp envp
89100 ins <- peek inp
90101 outs <- peek outp
91102 errs <- peek errp
92103 env <- peek envp
93− handleRequest f ins outs errs env
104+ handleRequest f ins outs errs env xsendfile
94105 fcgx_finish
95106
96107handleRequest :: W.Application
@@ -98,13 +109,14 @@ handleRequest :: W.Application
98109 -> StreamPtr
99110 -> StreamPtr
100111 -> Environ
112+ -> Maybe String -- sendfile
101113 -> IO ()
102−handleRequest f ins outs _errs env =
114+handleRequest f ins outs _errs env xsendfile =
103115 do
104116 vars <- environToTable env
105117 let input = sRead ins
106118 let hPut = sPutStr' outs
107− CGI.run'' vars (CGI.requestBodyFunc input) hPut f
119+ CGI.run'' vars (CGI.requestBodyFunc input) hPut xsendfile f
108120
109121data FCGX_Request
110122