@@ -26,26 +26,22 @@ import Network.Wai.Handler.Warp.ReadInt
2626import Network.Wai.Handler.Warp.Types
2727import Prelude hiding (lines)
2828import qualified Network.Wai.Handler.Warp.Timeout as Timeout
29+import qualified Control.Monad.Trans.Resource as Res
2930
3031-- FIXME come up with good values here
3132maxTotalHeaderLength :: Int
3233maxTotalHeaderLength = 50 * 1024
3334
34−parseRequest :: Connection
35− -> Port -> SockAddr
36− -> Source (ResourceT IO) ByteString
37− -> ResourceT IO (Request, IO (ResumableSource (ResourceT IO) ByteString))
38−parseRequest conn = parseRequestInternal conn Timeout.dummyHandle
39−
40−parseRequestInternal
35+parseRequest
4136 :: Connection
4237 -> Timeout.Handle
38+ -> Res.InternalState
4339 -> Port -> SockAddr
44− -> Source (ResourceT IO) ByteString
45− -> ResourceT IO (Request, IO (ResumableSource (ResourceT IO) ByteString))
46−parseRequestInternal conn timeoutHandle port remoteHost' src1 = do
40+ -> Source IO ByteString
41+ -> IO (Request, IO (ResumableSource IO ByteString))
42+parseRequest conn timeoutHandle internalState port remoteHost' src1 = do
4743 (src2, headers') <- src1 $$+ takeHeaders
48− parseRequest' conn timeoutHandle port headers' remoteHost' src2
44+ parseRequest' conn timeoutHandle internalState port headers' remoteHost' src2
4945
5046handleExpect :: Connection
5147 -> H.HttpVersion
@@ -64,13 +60,14 @@ handleExpect conn hv front (x:xs) = handleExpect conn hv (front . (x:)) xs
6460-- | Parse a set of header lines and body into a 'Request'.
6561parseRequest' :: Connection
6662 -> Timeout.Handle
63+ -> Res.InternalState
6764 -> Port
6865 -> [ByteString]
6966 -> SockAddr
70− -> ResumableSource (ResourceT IO) ByteString -- FIXME was buffered
71− -> ResourceT IO (Request, IO (ResumableSource (ResourceT IO) ByteString))
72−parseRequest' _ _ _ [] _ _ = throwIO $ NotEnoughLines []
73−parseRequest' conn timeoutHandle port (firstLine:otherLines) remoteHost' src = do
67+ -> ResumableSource IO ByteString -- FIXME was buffered
68+ -> IO (Request, IO (ResumableSource IO ByteString))
69+parseRequest' _ _ _ _ [] _ _ = throwIO $ NotEnoughLines []
70+parseRequest' conn timeoutHandle internalState port (firstLine:otherLines) remoteHost' src = do
7471 (method, rpath', gets, httpversion) <- parseFirst firstLine
7572 let (host',rpath)
7673 | S.null rpath' = ("", "/")
@@ -87,7 +84,7 @@ parseRequest' conn timeoutHandle port (firstLine:otherLines) remoteHost' src = d
8784 let serverName' = takeUntil 58 host -- ':'
8885 let chunked = maybe False ((== "chunked") . CI.foldCase)
8986 $ lookup hTransferEncoding heads
90− (rbody, getSource) <- liftIO $
87+ (rbody, getSource) <-
9188 if chunked
9289 then do
9390 ref <- I.newIORef (src, NeedLen)
@@ -125,6 +122,7 @@ parseRequest' conn timeoutHandle port (firstLine:otherLines) remoteHost' src = d
125122 then ChunkedBody
126123 else KnownLength $ fromIntegral len0
127124#endif
125+ , resourceInternalState = internalState
128126 }, getSource)
129127
130128{-# INLINE takeUntil #-}
@@ -136,7 +134,7 @@ takeUntil c bs =
136134
137135{-# INLINE parseFirst #-} -- FIXME is this inline necessary? the function is only called from one place and not exported
138136parseFirst :: ByteString
139− -> ResourceT IO (ByteString, ByteString, ByteString, H.HttpVersion)
137+ -> IO (ByteString, ByteString, ByteString, H.HttpVersion)
140138parseFirst s =
141139 case filter (not . S.null) $ S.splitWith (\c -> c == 32 || c == 9) s of -- ' '
142140 (method:query:http'') -> do
@@ -167,14 +165,14 @@ data THStatus = THStatus
167165 BSEndo -- bytestrings to be prepended
168166
169167{-# INLINE takeHeaders #-}
170−takeHeaders :: Sink ByteString (ResourceT IO) [ByteString]
168+takeHeaders :: Sink ByteString IO [ByteString]
171169takeHeaders =
172170 await >>= maybe (throwIO ConnectionClosedByPeer) (push (THStatus 0 id id))
173171
174−close :: Sink ByteString (ResourceT IO) a
172+close :: Sink ByteString IO a
175173close = throwIO IncompleteHeaders
176174
177−push :: THStatus -> ByteString -> Sink ByteString (ResourceT IO) [ByteString]
175+push :: THStatus -> ByteString -> Sink ByteString IO [ByteString]
178176push (THStatus len lines prepend) bs
179177 -- Too many bytes
180178 | len > maxTotalHeaderLength = throwIO OverLargeHeader