ContentBuilder and responseBuilder
This commit is contained in:
parent
48e8b1d9ca
commit
8d7d5ce167
@ -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
|
||||
|
||||
|
||||
@ -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'''
|
||||
|
||||
Loading…
Reference in New Issue
Block a user