@@ -1,6 +1,7 @@
11{-# LANGUAGE OverloadedStrings #-}
22{-# LANGUAGE ScopedTypeVariables #-}
33{-# LANGUAGE BangPatterns #-}
4+{-# LANGUAGE CPP #-}
45
56module Network.Wai.Handler.Warp.Response (
67 sendResponse
@@ -30,18 +31,19 @@ import qualified System.PosixCompat.Files as P
3031----------------------------------------------------------------
3132----------------------------------------------------------------
3233
33−sendResponse :: T.Handle
34− -> Request -> Connection -> Response -> ResourceT IO Bool
34+sendResponse :: Cleaner -> Request -> Connection -> Response
35+ -> ResourceT IO Bool
3536
3637----------------------------------------------------------------
3738
38−sendResponse th req conn (ResponseFile s hs fp mpart) =
39+sendResponse cleaner req conn (ResponseFile s hs path mpart) =
3940 headerAndLength >>= sendResponse'
4041 where
42+ th = threadHandle cleaner
4143 headerAndLength = case (readInt <$> checkLength hs, mpart) of
4244 (Just cl, _) -> return $ Right (hs, cl)
4345 (Nothing, Nothing) -> liftIO . try $ do
44− cl <- fromIntegral . P.fileSize <$> P.getFileStatus fp
46+ cl <- fromIntegral . P.fileSize <$> P.getFileStatus path
4547 return (addLength cl hs, cl)
4648 (Nothing, Just part) -> do
4749 let cl = fromIntegral $ filePartByteCount part
@@ -49,7 +51,7 @@ sendResponse th req conn (ResponseFile s hs fp mpart) =
4951
5052 sendResponse' (Right (lengthyHeaders, cl))
5153 | hasBody s req = liftIO $ do
52− connSendFile conn fp beg end (T.tickle th) [lheader]
54+ connSendFile conn path beg end (T.tickle th) [lheader] cleaner
5355 T.tickle th
5456 return isPersist
5557 | otherwise = liftIO $ do
@@ -65,13 +67,13 @@ sendResponse th req conn (ResponseFile s hs fp mpart) =
6567 (isPersist,_) = infoFromRequest req
6668
6769 sendResponse' (Left (_ :: SomeException)) =
68− sendResponse th req conn notFound
70+ sendResponse cleaner req conn notFound
6971 where
7072 notFound = responseLBS H.status404 [(H.hContentType, "text/plain")] "File not found"
7173
7274----------------------------------------------------------------
7375
74−sendResponse th req conn (ResponseBuilder s hs b)
76+sendResponse cleaner req conn (ResponseBuilder s hs b)
7577 | hasBody s req = liftIO $ do
7678 flip toByteStringIO body $ \bs -> do
7779 connSendAll conn bs
@@ -82,6 +84,7 @@ sendResponse th req conn (ResponseBuilder s hs b)
8284 T.tickle th
8385 return isPersist
8486 where
87+ th = threadHandle cleaner
8588 header = composeHeaderBuilder version s hs needsChunked
8689 body
8790 | needsChunked = header `mappend` chunkedTransferEncoding b
@@ -93,7 +96,7 @@ sendResponse th req conn (ResponseBuilder s hs b)
9396
9497----------------------------------------------------------------
9598
96−sendResponse th req conn (ResponseSource s hs bodyFlush)
99+sendResponse cleaner req conn (ResponseSource s hs bodyFlush)
97100 | hasBody s req = do
98101 let src = CL.sourceList [header] `mappend` cbody
99102 src $$ builderToByteString =$ connSink conn th
@@ -103,6 +106,7 @@ sendResponse th req conn (ResponseSource s hs bodyFlush)
103106 T.tickle th
104107 return isPersist
105108 where
109+ th = threadHandle cleaner
106110 header = composeHeaderBuilder version s hs needsChunked
107111 body = mapOutput (\x -> case x of
108112 Flush -> flush