on master help sign in
Disable chunking for HTTP 1.0 connections
commit689ddc9518718cfc4c0ada8f5c6861de67280ec6 authorMichael Snoyman <michael@snoyman.com> dateFri 24 Dec 2010, 12:20 (16 years ago) parent781d400
1 file changed+8−3
Network/Wai/Handler/Warp.hs+8−3
Network/Wai/Handler/Warp.hs+8−3
@@ -32,7 +32,7 @@ import Control.Exception (bracket, finally, Exception, throwIO)
3232import System.IO (Handle, hClose, hFlush)
3333import System.IO.Error (isEOFError, ioeGetHandle)
3434import Control.Concurrent (forkIO)
35−import Control.Monad (unless)
35+import Control.Monad (unless, when)
3636import Data.Maybe (fromMaybe)
3737
3838import Data.Typeable (Typeable)
@@ -79,7 +79,7 @@ serveConnection port app conn remoteHost' = do
7979 sendResponse (httpVersion env) conn res
8080 -- FIXME drain request body
8181 hFlush conn
82− serveConnection'
82+ when (isChunked $ httpVersion env) serveConnection'
8383
8484 catchEOFError :: IOError -> IO ()
8585 catchEOFError e | isEOFError e = case ioeGetHandle e of
@@ -175,7 +175,9 @@ headers httpversion status responseHeaders = mconcat
175175 , fromByteString $ statusMessage status
176176 , fromByteString "\r\n"
177177 , mconcat $ map go responseHeaders
178− , fromByteString "Transfer-Encoding: chunked\r\n\r\n" -- FIXME perhaps put in non-chunked for HTTP 1.0 clients?
178+ , if isChunked httpversion
179+ then fromByteString "Transfer-Encoding: chunked\r\n\r\n"
180+ else fromByteString "\r\n"
179181 ]
180182 where
181183 go (x, y) = mconcat
@@ -185,6 +187,9 @@ headers httpversion status responseHeaders = mconcat
185187 , fromByteString "\r\n"
186188 ]
187189
190+isChunked :: HttpVersion -> Bool
191+isChunked = (==) http11
192+
188193sendResponse :: HttpVersion -> Handle -> Response -> IO ()
189194sendResponse hv handle res = do
190195 responseEnumerator res $ \s hs ->