diff --git a/Network/Wai/Handler/Warp/IORef.hs b/Network/Wai/Handler/Warp/IORef.hs
--- a/Network/Wai/Handler/Warp/IORef.hs
+++ b/Network/Wai/Handler/Warp/IORef.hs
@@ -1,5 +1,9 @@
 {-# LANGUAGE CPP #-}
 
+#ifndef MIN_VERSION_base
+#define MIN_VERSION_base(x,y,z) 1
+#endif
+
 module Network.Wai.Handler.Warp.IORef (
     module Data.IORef
 #if !MIN_VERSION_base(4,6,0)
diff --git a/Network/Wai/Handler/Warp/Request.hs b/Network/Wai/Handler/Warp/Request.hs
--- a/Network/Wai/Handler/Warp/Request.hs
+++ b/Network/Wai/Handler/Warp/Request.hs
@@ -203,7 +203,7 @@
     -- update the length, and continue processing.
     push' Nothing = do
         bst <- readSource' src
-        when (S.null bs) $ throwIO IncompleteHeaders
+        when (S.null bst) $ throwIO IncompleteHeaders
         push src status bst
       where
         len' = len + bsLen
@@ -241,6 +241,6 @@
 
 {-# INLINE checkCR #-}
 checkCR :: ByteString -> Int -> Int
-checkCR bs pos = if 13 == S.index bs p then p else pos -- 13 is CR
+checkCR bs pos = if pos > 0 && 13 == S.index bs p then p else pos -- 13 is CR
   where
     !p = pos - 1
diff --git a/Network/Wai/Handler/Warp/Timeout.hs b/Network/Wai/Handler/Warp/Timeout.hs
--- a/Network/Wai/Handler/Warp/Timeout.hs
+++ b/Network/Wai/Handler/Warp/Timeout.hs
@@ -42,6 +42,10 @@
   , TimeoutThread (..)
   ) where
 
+#ifndef MIN_VERSION_base
+#define MIN_VERSION_base(x,y,z) 1
+#endif
+
 #if MIN_VERSION_base(4,6,0)
 import Control.Concurrent (mkWeakThreadId, ThreadId)
 #else
diff --git a/test/RequestSpec.hs b/test/RequestSpec.hs
--- a/test/RequestSpec.hs
+++ b/test/RequestSpec.hs
@@ -59,6 +59,35 @@
     test "bytes=9500-" $ Just [HH.ByteRangeFrom 9500]
     test "foobytes=9500-" Nothing
     test "bytes=0-0,-1" $ Just [HH.ByteRangeFromTo 0 0, HH.ByteRangeSuffix 1]
+
+  describe "headerLines" $ do
+      it "can handle a nomarl case" $ do
+          src <- mkSourceFunc ["Status: 200\r\nContent-Type: text/plain\r\n\r\n"] >>= mkSource
+          x <- headerLines src
+          x `shouldBe` ["Status: 200", "Content-Type: text/plain"]
+
+      it "can handle a nasty case (1)" $ do
+          src <- mkSourceFunc ["Status: 200", "\r\nContent-Type: text/plain", "\r\n\r\n"] >>= mkSource
+          x <- headerLines src
+          x `shouldBe` ["Status: 200", "Content-Type: text/plain"]
+
+      it "can handle a nasty case (1)" $ do
+          src <- mkSourceFunc ["Status: 200", "\r", "\nContent-Type: text/plain", "\r", "\n\r\n"] >>= mkSource
+          x <- headerLines src
+          x `shouldBe` ["Status: 200", "Content-Type: text/plain"]
+
+      it "can handle a nasty case (1)" $ do
+          src <- mkSourceFunc ["Status: 200", "\r", "\n", "Content-Type: text/plain", "\r", "\n", "\r", "\n"] >>= mkSource
+          x <- headerLines src
+          x `shouldBe` ["Status: 200", "Content-Type: text/plain"]
+
+      it "can handle an illegal case (1)" $ do
+          src <- mkSourceFunc ["\nStatus:", "\n 200", "\nContent-Type: text/plain", "\r\n\r\n"] >>= mkSource
+          x <- headerLines src
+          x `shouldBe` []
+          y <- headerLines src
+          y `shouldBe` ["Status: 200", "Content-Type: text/plain"]
+
   where
     blankSafe = headerLinesList ["f", "oo\n", "bar\nbaz\n\r\n"]
     whiteSafe = headerLinesList ["foo\r\nbar\r\nbaz\r\n\r\n hi there"]
@@ -101,3 +130,16 @@
 
 overLargeHeader :: Selector InvalidRequest
 overLargeHeader e = e == OverLargeHeader
+
+mkSourceFunc :: [S8.ByteString] -> IO (IO S8.ByteString)
+mkSourceFunc bss = do
+    ref <- newIORef bss
+    return $ reader ref
+  where
+    reader ref = do
+        xss <- readIORef ref
+        case xss of
+            []     -> return S.empty
+            (x:xs) -> do
+                writeIORef ref xs
+                return x
diff --git a/warp.cabal b/warp.cabal
--- a/warp.cabal
+++ b/warp.cabal
@@ -1,5 +1,5 @@
 Name:                warp
-Version:             3.0.0.6
+Version:             3.0.0.7
 Synopsis:            A fast, light-weight web server for WAI applications.
 License:             MIT
 License-file:        LICENSE
