@@ -263,14 +263,10 @@ plainHTTP :: TLSSettings -> Socket -> I.IORef B.ByteString -> IO (Connection, Bo
263263plainHTTP TLSSettings{..} s cachedRef = case onInsecure of
264264 AllowInsecure -> do
265265 conn' <- socketConnection s
266− let newRecv = do
267− bs <- I.readIORef cachedRef
268− if B.null bs
269− then connRecv conn'
270− else do
271− I.writeIORef cachedRef B.empty
272− return bs
273− return (conn' { connRecv = newRecv }, False)
266+ let conn'' = conn'
267+ { connRecv = recvCheckRef cachedRef (connRecv conn')
268+ }
269+ return (conn'', False)
274270 DenyInsecure lbs -> do
275271 sendAll s "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n"
276272 mapM_ (sendAll s) $ L.toChunks lbs
@@ -299,6 +295,20 @@ getNext cachedRef s size = do
299295
300296----------------------------------------------------------------
301297
298+-- | Modify the given receive function to first check the given @IORef@ for a
299+-- chunk of data. If present, takes the chunk of data from the @IORef@ and
300+-- empties out the @IORef@. Otherwise, calls the supplied receive function.
301+recvCheckRef :: I.IORef B.ByteString -> IO B.ByteString -> IO B.ByteString
302+recvCheckRef ref fallback = do
303+ bs <- I.readIORef ref
304+ if B.null bs
305+ then fallback
306+ else do
307+ I.writeIORef ref B.empty
308+ return bs
309+
310+----------------------------------------------------------------
311+
302312data WarpTLSException = InsecureConnectionDenied
303313 deriving (Show, Typeable)
304314instance Exception WarpTLSException