Type-specialized versions of sendChunk
This commit is contained in:
parent
968b96e0b1
commit
c16184eb40
@ -58,6 +58,11 @@ module Yesod.Core.Handler
|
||||
, respondSource
|
||||
, sendChunk
|
||||
, sendFlush
|
||||
, sendChunkBS
|
||||
, sendChunkLBS
|
||||
, sendChunkText
|
||||
, sendChunkLazyText
|
||||
, sendChunkHtml
|
||||
-- ** Redirecting
|
||||
, RedirectUrl (..)
|
||||
, redirect
|
||||
@ -153,6 +158,7 @@ import qualified Text.Blaze.Html.Renderer.Text as RenderText
|
||||
import Text.Hamlet (Html, HtmlUrl, hamlet)
|
||||
|
||||
import qualified Data.ByteString as S
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
import qualified Data.Map as Map
|
||||
|
||||
import Data.Conduit (Source)
|
||||
@ -941,3 +947,33 @@ sendChunk = yield . toFlushBuilder
|
||||
-- Since 1.2.0
|
||||
sendFlush :: Source (HandlerT site IO) (Flush Builder)
|
||||
sendFlush = yield Flush
|
||||
|
||||
-- | Type-specialized version of 'sendChunk' for strict @ByteString@s.
|
||||
--
|
||||
-- Since 1.2.0
|
||||
sendChunkBS :: S.ByteString -> Source (HandlerT site IO) (Flush Builder)
|
||||
sendChunkBS = sendChunk
|
||||
|
||||
-- | Type-specialized version of 'sendChunk' for lazy @ByteString@s.
|
||||
--
|
||||
-- Since 1.2.0
|
||||
sendChunkLBS :: L.ByteString -> Source (HandlerT site IO) (Flush Builder)
|
||||
sendChunkLBS = sendChunk
|
||||
|
||||
-- | Type-specialized version of 'sendChunk' for strict @Text@s.
|
||||
--
|
||||
-- Since 1.2.0
|
||||
sendChunkText :: T.Text -> Source (HandlerT site IO) (Flush Builder)
|
||||
sendChunkText = sendChunk
|
||||
|
||||
-- | Type-specialized version of 'sendChunk' for lazy @Text@s.
|
||||
--
|
||||
-- Since 1.2.0
|
||||
sendChunkLazyText :: TL.Text -> Source (HandlerT site IO) (Flush Builder)
|
||||
sendChunkLazyText = sendChunk
|
||||
|
||||
-- | Type-specialized version of 'sendChunk' for @Html@s.
|
||||
--
|
||||
-- Since 1.2.0
|
||||
sendChunkHtml :: Html -> Source (HandlerT site IO) (Flush Builder)
|
||||
sendChunkHtml = sendChunk
|
||||
|
||||
@ -13,7 +13,8 @@ app :: LiteApp
|
||||
app = dispatchTo $ respondSource typeHtml $ do
|
||||
sendChunk ("Hello " :: String)
|
||||
sendChunk ("World" :: ByteString)
|
||||
sendChunk ("!" :: Text)
|
||||
sendChunk ("!\n" :: Text)
|
||||
sendChunkHtml "<&>"
|
||||
|
||||
test :: String
|
||||
-> (SResponse -> Session ())
|
||||
@ -28,4 +29,4 @@ specs :: Spec
|
||||
specs = describe "Streaming" $ do
|
||||
test "works" $ \sres -> do
|
||||
assertStatus 200 sres
|
||||
assertBody "Hello World!" sres
|
||||
assertBody "Hello World!\n<&>" sres
|
||||
|
||||
Loading…
Reference in New Issue
Block a user