diff --git a/ChangeLog.md b/ChangeLog.md
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,7 @@
+## 1.6.6
+
+* `defaultErrorHandler` handles text/plain requests [#1522](https://github.com/yesodweb/yesod/pull/1520)
+
 ## 1.6.5
 
 * Add `fileSourceByteString` [#1503](https://github.com/yesodweb/yesod/pull/1503)
diff --git a/Yesod/Core/Class/Handler.hs b/Yesod/Core/Class/Handler.hs
--- a/Yesod/Core/Class/Handler.hs
+++ b/Yesod/Core/Class/Handler.hs
@@ -16,9 +16,6 @@
 import Control.Monad.Logger (MonadLogger)
 import Control.Monad.Trans.Resource (MonadResource)
 import Control.Monad.Trans.Class (lift)
-#if __GLASGOW_HASKELL__ < 710
-import Data.Monoid (Monoid)
-#endif
 import Data.Conduit.Internal (Pipe, ConduitM)
 
 import Control.Monad.Trans.Identity ( IdentityT)
diff --git a/Yesod/Core/Class/Yesod.hs b/Yesod/Core/Class/Yesod.hs
--- a/Yesod/Core/Class/Yesod.hs
+++ b/Yesod/Core/Class/Yesod.hs
@@ -2,7 +2,6 @@
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE QuasiQuotes       #-}
 {-# LANGUAGE TemplateHaskell   #-}
-{-# LANGUAGE CPP               #-}
 module Yesod.Core.Class.Yesod where
 
 import           Yesod.Core.Content
@@ -14,9 +13,6 @@
 import           Data.Text.Encoding                 (encodeUtf8Builder)
 import           Control.Arrow                      ((***), second)
 import           Control.Exception                  (bracket)
-#if __GLASGOW_HASKELL__ < 710
-import           Control.Applicative                ((<$>))
-#endif
 import           Control.Monad                      (forM, when, void)
 import           Control.Monad.IO.Class             (MonadIO (liftIO))
 import           Control.Monad.Logger               (LogLevel (LevelInfo, LevelOther),
@@ -615,6 +611,7 @@
         let path' = TE.decodeUtf8With TEE.lenientDecode $ W.rawPathInfo r
         defaultMessageWidget "Not Found" [hamlet|<p>#{path'}|]
     provideRep $ return $ object ["message" .= ("Not Found" :: Text)]
+    provideRep $ return $ ("Not Found" :: Text)
 
 -- For API requests.
 -- For a user with a browser,
@@ -638,6 +635,7 @@
         let apair u = ["authentication_url" .= rend u]
             content = maybe [] apair (authRoute site)
         return $ object $ ("message" .= ("Not logged in"::Text)):content
+    provideRep $ return $ ("Not logged in" :: Text)
 
 defaultErrorHandler (PermissionDenied msg) = selectRep $ do
     provideRep $ defaultLayout $ defaultMessageWidget
@@ -645,6 +643,7 @@
         [hamlet|<p>#{msg}|]
     provideRep $
         return $ object ["message" .= ("Permission Denied. " <> msg)]
+    provideRep $ return $ "Permission Denied. " <> msg
 
 defaultErrorHandler (InvalidArgs ia) = selectRep $ do
     provideRep $ defaultLayout $ defaultMessageWidget
@@ -655,6 +654,8 @@
                     <li>#{msg}
         |]
     provideRep $ return $ object ["message" .= ("Invalid Arguments" :: Text), "errors" .= ia]
+    provideRep $ return $ ("Invalid Arguments: " <> T.intercalate " " ia)
+
 defaultErrorHandler (InternalError e) = do
     $logErrorS "yesod-core" e
     selectRep $ do
@@ -662,11 +663,14 @@
             "Internal Server Error"
             [hamlet|<pre>#{e}|]
         provideRep $ return $ object ["message" .= ("Internal Server Error" :: Text), "error" .= e]
+        provideRep $ return $ "Internal Server Error: " <> e
+
 defaultErrorHandler (BadMethod m) = selectRep $ do
     provideRep $ defaultLayout $ defaultMessageWidget
         "Method Not Supported"
         [hamlet|<p>Method <code>#{S8.unpack m}</code> not supported|]
     provideRep $ return $ object ["message" .= ("Bad method" :: Text), "method" .= TE.decodeUtf8With TEE.lenientDecode m]
+    provideRep $ return $ "Bad Method " <> TE.decodeUtf8With TEE.lenientDecode m
 
 asyncHelper :: (url -> [x] -> Text)
          -> [Script url]
diff --git a/Yesod/Core/Content.hs b/Yesod/Core/Content.hs
--- a/Yesod/Core/Content.hs
+++ b/Yesod/Core/Content.hs
@@ -4,7 +4,6 @@
 {-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE Rank2Types #-}
 {-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE CPP #-}
 module Yesod.Core.Content
     ( -- * Content
       Content (..)
@@ -56,9 +55,6 @@
 import Data.Text.Encoding (encodeUtf8Builder)
 import qualified Data.Text.Lazy as TL
 import Data.ByteString.Builder (Builder, byteString, lazyByteString, stringUtf8)
-#if __GLASGOW_HASKELL__ < 710
-import Data.Monoid (mempty)
-#endif
 import Text.Hamlet (Html)
 import Text.Blaze.Html.Renderer.Utf8 (renderHtmlBuilder)
 import Data.Conduit (Flush (Chunk), SealedConduitT, mapOutput)
diff --git a/Yesod/Core/Dispatch.hs b/Yesod/Core/Dispatch.hs
--- a/Yesod/Core/Dispatch.hs
+++ b/Yesod/Core/Dispatch.hs
@@ -3,7 +3,6 @@
 {-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE CPP #-}
 module Yesod.Core.Dispatch
     ( -- * Quasi-quoted routing
       parseRoutes
@@ -48,9 +47,6 @@
 import Data.ByteString.Lazy.Char8 ()
 
 import Data.Text (Text)
-#if __GLASGOW_HASKELL__ < 710
-import Data.Monoid (mappend)
-#endif
 import qualified Data.ByteString as S
 import qualified Data.ByteString.Lazy as BL
 import qualified Data.ByteString.Char8 as S8
@@ -61,7 +57,7 @@
 import Yesod.Core.Class.Yesod
 import Yesod.Core.Class.Dispatch
 import Yesod.Core.Internal.Run
-import Safe (readMay)
+import Text.Read (readMaybe)
 import System.Environment (getEnvironment)
 import qualified System.Random as Random
 import Control.AutoUpdate (mkAutoUpdate, defaultUpdateSettings, updateAction, updateFreq)
@@ -243,7 +239,7 @@
     case lookup "PORT" env of
         Nothing -> error "warpEnv: no PORT environment variable found"
         Just portS ->
-            case readMay portS of
+            case readMaybe portS of
                 Nothing -> error $ "warpEnv: invalid PORT environment variable: " ++ show portS
                 Just port -> warp port site
 
diff --git a/Yesod/Core/Handler.hs b/Yesod/Core/Handler.hs
--- a/Yesod/Core/Handler.hs
+++ b/Yesod/Core/Handler.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP                        #-}
 {-# LANGUAGE FlexibleContexts           #-}
 {-# LANGUAGE ConstraintKinds            #-}
 {-# LANGUAGE FlexibleInstances          #-}
@@ -195,10 +194,6 @@
                                                 mkFileInfoLBS, mkFileInfoSource)
 
 
-#if __GLASGOW_HASKELL__ < 710
-import           Control.Applicative           ((<$>))
-import           Data.Monoid                   (mempty, mappend)
-#endif
 import           Control.Applicative           ((<|>))
 import qualified Data.CaseInsensitive          as CI
 import           Control.Exception             (evaluate, SomeException, throwIO)
@@ -249,7 +244,6 @@
 import           Yesod.Core.Types
 import           Yesod.Routes.Class            (Route)
 import           Data.ByteString.Builder (Builder)
-import           Safe (headMay)
 import           Data.CaseInsensitive (CI, original)
 import qualified Data.Conduit.List as CL
 import           Control.Monad.Trans.Resource  (MonadResource, InternalState, runResourceT, withInternalState, getInternalState, liftResourceT, resourceForkIO)
@@ -606,7 +600,7 @@
 -- | Gets just the last message in the user's session,
 -- discards the rest and the status
 getMessage :: MonadHandler m => m (Maybe Html)
-getMessage = fmap (fmap snd . headMay) getMessages
+getMessage = fmap (fmap snd . listToMaybe) getMessages
 
 -- | Bypass remaining handler code and output the given file.
 --
@@ -1322,7 +1316,7 @@
     tryAccept ct =
         if subType == "*"
           then if mainType == "*"
-                 then headMay reps
+                 then listToMaybe reps
                  else Map.lookup mainType mainTypeMap
           else lookupAccept ct
         where
diff --git a/Yesod/Core/Internal/LiteApp.hs b/Yesod/Core/Internal/LiteApp.hs
--- a/Yesod/Core/Internal/LiteApp.hs
+++ b/Yesod/Core/Internal/LiteApp.hs
@@ -1,9 +1,6 @@
 {-# LANGUAGE TypeFamilies, PatternGuards, CPP #-}
 module Yesod.Core.Internal.LiteApp where
 
-#if __GLASGOW_HASKELL__ < 710
-import Data.Monoid
-#endif
 #if !(MIN_VERSION_base(4,11,0))
 import Data.Semigroup (Semigroup(..))
 #endif
diff --git a/Yesod/Core/Internal/Run.hs b/Yesod/Core/Internal/Run.hs
--- a/Yesod/Core/Internal/Run.hs
+++ b/Yesod/Core/Internal/Run.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP               #-}
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE PatternGuards     #-}
 {-# LANGUAGE RankNTypes        #-}
@@ -9,10 +8,6 @@
 module Yesod.Core.Internal.Run where
 
 
-#if __GLASGOW_HASKELL__ < 710
-import           Data.Monoid                  (Monoid, mempty)
-import           Control.Applicative          ((<$>))
-#endif
 import Yesod.Core.Internal.Response
 import           Data.ByteString.Builder      (toLazyByteString)
 import qualified Data.ByteString.Lazy         as BL
@@ -287,10 +282,8 @@
           , vault          = mempty
           , requestBodyLength = KnownLength 0
           , requestHeaderRange = Nothing
-#if MIN_VERSION_wai(3,2,0)
           , requestHeaderReferer = Nothing
           , requestHeaderUserAgent = Nothing
-#endif
           }
       fakeRequest =
         YesodRequest
diff --git a/Yesod/Core/Internal/TH.hs b/Yesod/Core/Internal/TH.hs
--- a/Yesod/Core/Internal/TH.hs
+++ b/Yesod/Core/Internal/TH.hs
@@ -3,7 +3,6 @@
 {-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE FlexibleContexts #-}
 module Yesod.Core.Internal.TH where
 
@@ -17,9 +16,6 @@
 
 import Data.ByteString.Lazy.Char8 ()
 import Data.List (foldl')
-#if __GLASGOW_HASKELL__ < 710
-import Control.Applicative ((<$>))
-#endif
 import Control.Monad (replicateM, void)
 import Text.Parsec (parse, many1, many, eof, try, option, sepBy1)
 import Text.ParserCombinators.Parsec.Char (alphaNum, spaces, string, char)
@@ -126,11 +122,7 @@
                -> Q([Dec],[Dec])
 mkYesodGeneral appCxt' namestr mtys isSub f resS = do
     let appCxt = fmap (\(c:rest) -> 
-#if MIN_VERSION_template_haskell(2,10,0)
             foldl' (\acc v -> acc `AppT` nameToType v) (ConT $ mkName c) rest
-#else
-            ClassP (mkName c) $ fmap nameToType rest
-#endif
           ) appCxt'
     mname <- lookupTypeName namestr
     arity <- case mname of
@@ -140,13 +132,8 @@
                    case info of
                      TyConI dec ->
                        case dec of
-#if MIN_VERSION_template_haskell(2,11,0)
                          DataD _ _ vs _ _ _ -> length vs
                          NewtypeD _ _ vs _ _ _ -> length vs
-#else
-                         DataD _ _ vs _ _ -> length vs
-                         NewtypeD _ _ vs _ _ -> length vs
-#endif
                          TySynD _ vs _ -> length vs
                          _ -> 0
                      _ -> 0
@@ -230,8 +217,4 @@
     return $ LetE [fun] (VarE helper)
 
 instanceD :: Cxt -> Type -> [Dec] -> Dec
-#if MIN_VERSION_template_haskell(2,11,0)
 instanceD = InstanceD Nothing
-#else
-instanceD = InstanceD
-#endif
diff --git a/Yesod/Core/Types.hs b/Yesod/Core/Types.hs
--- a/Yesod/Core/Types.hs
+++ b/Yesod/Core/Types.hs
@@ -11,11 +11,6 @@
 module Yesod.Core.Types where
 
 import qualified Data.ByteString.Builder            as BB
-#if __GLASGOW_HASKELL__ < 710
-import           Control.Applicative                (Applicative (..))
-import           Control.Applicative                ((<$>))
-import           Data.Monoid                        (Monoid (..))
-#endif
 import           Control.Arrow                      (first)
 import           Control.Exception                  (Exception)
 import           Control.Monad                      (ap)
@@ -57,7 +52,6 @@
 import           Yesod.Routes.Class                 (RenderRoute (..), ParseRoute (..))
 import           Control.Monad.Reader               (MonadReader (..))
 import Control.DeepSeq (NFData (rnf))
-import Control.DeepSeq.Generics (genericRnf)
 import Yesod.Core.TypeCache (TypeMap, KeyedTypeMap)
 import Control.Monad.Logger (MonadLoggerIO (..))
 import UnliftIO (MonadUnliftIO (..), UnliftIO (..))
@@ -323,8 +317,7 @@
     | PermissionDenied !Text
     | BadMethod !H.Method
     deriving (Show, Eq, Typeable, Generic)
-instance NFData ErrorResponse where
-    rnf = genericRnf
+instance NFData ErrorResponse
 
 ----- header stuff
 -- | Headers to be added to a 'Result'.
diff --git a/Yesod/Core/Unsafe.hs b/Yesod/Core/Unsafe.hs
--- a/Yesod/Core/Unsafe.hs
+++ b/Yesod/Core/Unsafe.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP #-}
 -- | This is designed to be used as
 --
 -- > import qualified Yesod.Core.Unsafe as Unsafe
@@ -10,9 +9,6 @@
 
 import Yesod.Core.Types
 import Yesod.Core.Class.Yesod
-#if __GLASGOW_HASKELL__ < 710
-import Data.Monoid            (mempty, mappend)
-#endif
 import Control.Monad.IO.Class (MonadIO)
 
 -- | designed to be used as
diff --git a/Yesod/Core/Widget.hs b/Yesod/Core/Widget.hs
--- a/Yesod/Core/Widget.hs
+++ b/Yesod/Core/Widget.hs
@@ -8,7 +8,6 @@
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE TypeSynonymInstances #-}
 {-# LANGUAGE UndecidableInstances #-}
-{-# LANGUAGE CPP #-}
 -- | Widgets combine HTML with JS and CSS dependencies with a unique identifier
 -- generator, allowing you to create truly modular HTML components.
 module Yesod.Core.Widget
@@ -57,9 +56,6 @@
 import Text.Julius
 import Yesod.Routes.Class
 import Yesod.Core.Handler (getMessageRender, getUrlRenderParams)
-#if __GLASGOW_HASKELL__ < 710
-import Control.Applicative ((<$>))
-#endif
 import Text.Shakespeare.I18N (RenderMessage)
 import Data.Text (Text)
 import qualified Data.Map as Map
diff --git a/Yesod/Routes/TH/ParseRoute.hs b/Yesod/Routes/TH/ParseRoute.hs
--- a/Yesod/Routes/TH/ParseRoute.hs
+++ b/Yesod/Routes/TH/ParseRoute.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE TemplateHaskell #-}
 module Yesod.Routes.TH.ParseRoute
     ( -- ** ParseRoute
@@ -45,8 +44,4 @@
     fixDispatch x = x
 
 instanceD :: Cxt -> Type -> [Dec] -> Dec
-#if MIN_VERSION_template_haskell(2,11,0)
 instanceD = InstanceD Nothing
-#else
-instanceD = InstanceD
-#endif
diff --git a/Yesod/Routes/TH/RenderRoute.hs b/Yesod/Routes/TH/RenderRoute.hs
--- a/Yesod/Routes/TH/RenderRoute.hs
+++ b/Yesod/Routes/TH/RenderRoute.hs
@@ -7,22 +7,14 @@
     ) where
 
 import Yesod.Routes.TH.Types
-#if MIN_VERSION_template_haskell(2,11,0)
 import Language.Haskell.TH (conT)
-#endif
 import Language.Haskell.TH.Syntax
-#if MIN_VERSION_template_haskell(2,11,0)
 import Data.Bits (xor)
-#endif
 import Data.Maybe (maybeToList)
 import Control.Monad (replicateM)
 import Data.Text (pack)
 import Web.PathPieces (PathPiece (..), PathMultiPiece (..))
 import Yesod.Routes.Class
-#if __GLASGOW_HASKELL__ < 710
-import Control.Applicative ((<$>))
-import Data.Monoid (mconcat)
-#endif
 
 -- | Generate the constructors of a route data type.
 mkRouteCons :: [ResourceTree Type] -> Q ([Con], [Dec])
@@ -50,10 +42,8 @@
         (cons, decs) <- mkRouteCons children
 #if MIN_VERSION_template_haskell(2,12,0)
         dec <- DataD [] (mkName name) [] Nothing cons <$> fmap (pure . DerivClause Nothing) (mapM conT [''Show, ''Read, ''Eq])
-#elif MIN_VERSION_template_haskell(2,11,0)
-        dec <- DataD [] (mkName name) [] Nothing cons <$> mapM conT [''Show, ''Read, ''Eq]
 #else
-        let dec = DataD [] (mkName name) [] cons [''Show, ''Read, ''Eq]
+        dec <- DataD [] (mkName name) [] Nothing cons <$> mapM conT [''Show, ''Read, ''Eq]
 #endif
         return ([con], dec : decs)
       where
@@ -154,12 +144,9 @@
 #if MIN_VERSION_template_haskell(2,12,0)
     did <- DataInstD [] ''Route [typ] Nothing cons <$> fmap (pure . DerivClause Nothing) (mapM conT (clazzes False))
     let sds = fmap (\t -> StandaloneDerivD Nothing cxt $ ConT t `AppT` ( ConT ''Route `AppT` typ)) (clazzes True)
-#elif MIN_VERSION_template_haskell(2,11,0)
+#else
     did <- DataInstD [] ''Route [typ] Nothing cons <$> mapM conT (clazzes False)
     let sds = fmap (\t -> StandaloneDerivD cxt $ ConT t `AppT` ( ConT ''Route `AppT` typ)) (clazzes True)
-#else
-    let did = DataInstD [] ''Route [typ] cons clazzes'
-    let sds = []
 #endif
     return $ instanceD cxt (ConT ''RenderRoute `AppT` typ)
         [ did
@@ -167,25 +154,14 @@
         ]
         : sds ++ decs
   where
-#if MIN_VERSION_template_haskell(2,11,0)
     clazzes standalone = if standalone `xor` null cxt then
           clazzes'
         else
           []
-#endif
     clazzes' = [''Show, ''Eq, ''Read]
 
-#if MIN_VERSION_template_haskell(2,11,0)
 notStrict :: Bang
 notStrict = Bang NoSourceUnpackedness NoSourceStrictness
-#else
-notStrict :: Strict
-notStrict = NotStrict
-#endif
 
 instanceD :: Cxt -> Type -> [Dec] -> Dec
-#if MIN_VERSION_template_haskell(2,11,0)
 instanceD = InstanceD Nothing
-#else
-instanceD = InstanceD
-#endif
diff --git a/Yesod/Routes/TH/RouteAttrs.hs b/Yesod/Routes/TH/RouteAttrs.hs
--- a/Yesod/Routes/TH/RouteAttrs.hs
+++ b/Yesod/Routes/TH/RouteAttrs.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE TemplateHaskell #-}
 {-# LANGUAGE RecordWildCards #-}
 module Yesod.Routes.TH.RouteAttrs
@@ -10,9 +9,6 @@
 import Language.Haskell.TH.Syntax
 import Data.Set (fromList)
 import Data.Text (pack)
-#if __GLASGOW_HASKELL__ < 710
-import Control.Applicative ((<$>))
-#endif
 
 mkRouteAttrsInstance :: Cxt -> Type -> [ResourceTree a] -> Q Dec
 mkRouteAttrsInstance cxt typ ress = do
@@ -42,8 +38,4 @@
     toText s = VarE 'pack `AppE` LitE (StringL s)
 
 instanceD :: Cxt -> Type -> [Dec] -> Dec
-#if MIN_VERSION_template_haskell(2,11,0)
 instanceD = InstanceD Nothing
-#else
-instanceD = InstanceD
-#endif
diff --git a/test/YesodCoreTest.hs b/test/YesodCoreTest.hs
--- a/test/YesodCoreTest.hs
+++ b/test/YesodCoreTest.hs
@@ -16,7 +16,12 @@
 import qualified YesodCoreTest.JsLoader as JsLoader
 import qualified YesodCoreTest.RequestBodySize as RequestBodySize
 import qualified YesodCoreTest.Json as Json
+
+-- Skip on Windows, see https://github.com/yesodweb/yesod/issues/1523#issuecomment-398278450
+#if !WINDOWS
 import qualified YesodCoreTest.RawResponse as RawResponse
+#endif
+
 import qualified YesodCoreTest.Streaming as Streaming
 import qualified YesodCoreTest.Reps as Reps
 import qualified YesodCoreTest.Auth as Auth
@@ -43,7 +48,9 @@
       JsLoader.specs
       RequestBodySize.specs
       Json.specs
+#if !WINDOWS
       RawResponse.specs
+#endif
       Streaming.specs
       Reps.specs
       Auth.specs
diff --git a/test/YesodCoreTest/RawResponse.hs b/test/YesodCoreTest/RawResponse.hs
--- a/test/YesodCoreTest/RawResponse.hs
+++ b/test/YesodCoreTest/RawResponse.hs
@@ -13,15 +13,13 @@
 import Data.Conduit
 import qualified Data.Conduit.Binary as CB
 import Data.Char (toUpper)
-import Control.Exception (try, IOException)
 import Data.Conduit.Network
-import Network.Socket (close)
 import Control.Concurrent (threadDelay)
-import Control.Concurrent.Async (withAsync)
+import Control.Concurrent.Async (race)
 import Control.Monad.Trans.Resource (register)
 import Data.IORef
-import Data.Streaming.Network (bindPortTCP)
 import Network.HTTP.Types (status200)
+import Network.Wai.Handler.Warp (testWithApplication)
 
 mkYesod "App" [parseRoutes|
 / HomeR GET
@@ -56,53 +54,38 @@
     flush
     send " world"
 
-getFreePort :: IO Int
-getFreePort = do
-    loop 43124
-  where
-    loop port = do
-        esocket <- try $ bindPortTCP port "*"
-        case esocket of
-            Left (_ :: IOException) -> loop (succ port)
-            Right socket -> do
-                close socket
-                return port
+allowFiveSeconds :: IO a -> IO a
+allowFiveSeconds = fmap (either id id) . race (threadDelay 5000000 >> error "timed out")
 
 specs :: Spec
 specs = do
     describe "RawResponse" $ do
-        it "works" $ do
-            port <- getFreePort
-            withAsync (warp port App) $ \_ -> do
-                threadDelay 100000
-                runTCPClient (clientSettings port "127.0.0.1") $ \ad -> do
-                    runConduit $ yield "GET / HTTP/1.1\r\n\r\nhello" .| appSink ad
-                    runConduit (appSource ad .| CB.take 6) >>= (`shouldBe` "0HELLO")
-                    runConduit $ yield "WORLd" .| appSink ad
-                    runConduit (appSource ad .| await) >>= (`shouldBe` Just "WORLD")
+        it "works" $ allowFiveSeconds $ testWithApplication (toWaiApp App) $ \port -> do
+            runTCPClient (clientSettings port "127.0.0.1") $ \ad -> do
+                runConduit $ yield "GET / HTTP/1.1\r\n\r\nhello" .| appSink ad
+                runConduit (appSource ad .| CB.take 6) >>= (`shouldBe` "0HELLO")
+                runConduit $ yield "WORLd" .| appSink ad
+                runConduit (appSource ad .| await) >>= (`shouldBe` Just "WORLD")
 
-    let body req = do
-            port <- getFreePort
-            withAsync (warp port App) $ \_ -> do
-                threadDelay 100000
-                runTCPClient (clientSettings port "127.0.0.1") $ \ad -> do
-                    runConduit $ yield req .| appSink ad
-                    runConduit $ appSource ad .| CB.lines .| do
-                        let loop = do
-                                x <- await
-                                case x of
-                                    Nothing -> return ()
-                                    Just "\r" -> return ()
-                                    _ -> loop
-                        loop
+    let body req = allowFiveSeconds $ testWithApplication (toWaiApp App) $ \port -> do
+            runTCPClient (clientSettings port "127.0.0.1") $ \ad -> do
+                runConduit $ yield req .| appSink ad
+                runConduit $ appSource ad .| CB.lines .| do
+                    let loop = do
+                            x <- await
+                            case x of
+                                Nothing -> return ()
+                                Just "\r" -> return ()
+                                _ -> loop
+                    loop
 
-                        Just "0005\r" <- await
-                        Just "hello\r" <- await
+                    Just "0005\r" <- await
+                    Just "hello\r" <- await
 
-                        Just "0006\r" <- await
-                        Just " world\r" <- await
+                    Just "0006\r" <- await
+                    Just " world\r" <- await
 
-                        return ()
+                    return ()
     it "sendWaiResponse + responseStream" $ do
         body "GET /wai-stream HTTP/1.1\r\n\r\n"
     it "sendWaiApplication + responseStream" $ do
diff --git a/yesod-core.cabal b/yesod-core.cabal
--- a/yesod-core.cabal
+++ b/yesod-core.cabal
@@ -1,5 +1,5 @@
 name:            yesod-core
-version:         1.6.5
+version:         1.6.6
 license:         MIT
 license-file:    LICENSE
 author:          Michael Snoyman <michael@snoyman.com>
@@ -22,48 +22,43 @@
 
 library
     build-depends:   base                  >= 4.9      && < 5
-                   , time                  >= 1.5
-                   , wai                   >= 3.0
-                   , wai-extra             >= 3.0.7
+                   , aeson                 >= 1.0
+                   , auto-update
+                   , blaze-html            >= 0.5
+                   , blaze-markup          >= 0.7.1
+                   , byteable
                    , bytestring            >= 0.10.2
-                   , text                  >= 0.7
-                   , template-haskell
-                   , path-pieces           >= 0.1.2    && < 0.3
-                   , shakespeare           >= 2.0
-                   , transformers          >= 0.4
-                   , mtl
-                   , clientsession         >= 0.9.1    && < 0.10
-                   , random                >= 1.0.0.2  && < 1.2
+                   , case-insensitive      >= 0.2
                    , cereal                >= 0.3
-                   , old-locale            >= 1.0.0.2  && < 1.1
+                   , clientsession         >= 0.9.1    && < 0.10
+                   , conduit               >= 1.3
+                   , conduit-extra
                    , containers            >= 0.2
-                   , unordered-containers  >= 0.2
                    , cookie                >= 0.4.3    && < 0.5
+                   , deepseq               >= 1.3
+                   , fast-logger           >= 2.2
                    , http-types            >= 0.7
-                   , case-insensitive      >= 0.2
+                   , monad-logger          >= 0.3.10   && < 0.4
+                   , mtl
                    , parsec                >= 2        && < 3.2
-                   , directory             >= 1
+                   , path-pieces           >= 0.1.2    && < 0.3
+                   , random                >= 1.0.0.2  && < 1.2
+                   , resourcet             >= 1.2
+                   , rio
+                   , shakespeare           >= 2.0
+                   , template-haskell      >= 2.11
+                   , text                  >= 0.7
+                   , time                  >= 1.5
+                   , transformers          >= 0.4
+                   , unix-compat
+                   , unliftio
+                   , unordered-containers  >= 0.2
                    , vector                >= 0.9      && < 0.13
-                   , aeson                 >= 1.0
-                   , fast-logger           >= 2.2
+                   , wai                   >= 3.2
+                   , wai-extra             >= 3.0.7
                    , wai-logger            >= 0.2
-                   , monad-logger          >= 0.3.10   && < 0.4
-                   , conduit               >= 1.3
-                   , resourcet             >= 1.2
-                   , blaze-html            >= 0.5
-                   , blaze-markup          >= 0.7.1
-                   , safe
                    , warp                  >= 3.0.2
-                   , unix-compat
-                   , conduit-extra
-                   , deepseq               >= 1.3
-                   , deepseq-generics
-                   , primitive
                    , word8
-                   , auto-update
-                   , semigroups
-                   , byteable
-                   , unliftio
 
     exposed-modules: Yesod.Core
                      Yesod.Core.Content
@@ -173,44 +168,43 @@
                    YesodCoreTest.YesodTest
 
     cpp-options:   -DTEST
-    build-depends: base
-                  ,hspec >= 1.3
-                  ,hspec-expectations
-                  ,clientsession
-                  ,wai >= 3.0
-                  ,yesod-core
-                  ,bytestring
-                  ,text
-                  ,http-types
-                  , random
-                  ,HUnit
-                  ,QuickCheck >= 2 && < 3
-                  ,transformers
+    if os(windows)
+        cpp-options: -DWINDOWS
+    build-depends:  base
+                  , async
+                  , bytestring
+                  , clientsession
                   , conduit
+                  , conduit-extra
                   , containers
-                  , resourcet
+                  , cookie >= 0.4.1    && < 0.5
+                  , hspec >= 1.3
+                  , hspec-expectations
+                  , http-types
                   , network
-                  , async
-                  , conduit-extra
+                  , random
+                  , resourcet
                   , shakespeare
                   , streaming-commons
-                  , wai-extra
-                  , cookie >= 0.4.1    && < 0.5
+                  , text
+                  , transformers
                   , unliftio
-    ghc-options:     -Wall
+                  , wai >= 3.0
+                  , wai-extra
+                  , warp
+                  , yesod-core
+    ghc-options:     -Wall -threaded
     extensions: TemplateHaskell
 
 benchmark widgets
     type: exitcode-stdio-1.0
     hs-source-dirs: bench
     build-depends:  base
-                  , gauge
-                  , bytestring
-                  , text
-                  , transformers
-                  , yesod-core
                   , blaze-html
+                  , bytestring
+                  , gauge
                   , shakespeare
+                  , text
     main-is:        widget.hs
     ghc-options:    -Wall -O2
 
