diff --git a/Yesod/Content.hs b/Yesod/Content.hs index 10a83557..65a77038 100644 --- a/Yesod/Content.hs +++ b/Yesod/Content.hs @@ -70,15 +70,16 @@ import Test.HUnit hiding (Test) #endif import Data.Enumerator (Enumerator) -import Blaze.ByteString.Builder (Builder) +import Blaze.ByteString.Builder (Builder, fromByteString, fromLazyByteString) +import Data.Monoid (mempty) -data Content = ContentLBS L.ByteString +data Content = ContentBuilder Builder | ContentEnum (forall a. Enumerator Builder IO a) | ContentFile FilePath -- | Zero-length enumerator. emptyContent :: Content -emptyContent = ContentLBS L.empty +emptyContent = ContentBuilder mempty -- | Anything which can be converted into 'Content'. Most of the time, you will -- want to use the 'ContentEnum' constructor. An easier approach will be to use @@ -88,13 +89,13 @@ class ToContent a where toContent :: a -> Content instance ToContent B.ByteString where - toContent = ContentLBS . L.fromChunks . return + toContent = ContentBuilder . fromByteString instance ToContent L.ByteString where - toContent = ContentLBS + toContent = ContentBuilder . fromLazyByteString instance ToContent T.Text where toContent = toContent . Data.Text.Encoding.encodeUtf8 instance ToContent Text where - toContent = ContentLBS . Data.Text.Lazy.Encoding.encodeUtf8 + toContent = toContent . Data.Text.Lazy.Encoding.encodeUtf8 instance ToContent String where toContent = toContent . T.pack diff --git a/Yesod/Dispatch.hs b/Yesod/Dispatch.hs index 174c707b..26f629bc 100644 --- a/Yesod/Dispatch.hs +++ b/Yesod/Dispatch.hs @@ -339,7 +339,7 @@ toWaiApp' y key' segments env = do hs''' = ("Content-Type", charsToBs ct) : hs'' return $ case c of - ContentLBS lbs -> W.ResponseLBS s hs''' lbs + ContentBuilder b -> W.responseBuilder s hs''' b ContentFile fp -> W.ResponseFile s hs''' fp ContentEnum e -> W.ResponseEnumerator $ \iter -> run_ $ e $$ iter s hs'''