Fix issue #1011: NewlineFraming encodes newline after each element
This commit is contained in:
parent
17f9237980
commit
f1eb5f93a8
2 changed files with 4 additions and 11 deletions
|
@ -187,20 +187,13 @@ instance FramingUnrender NoFraming where
|
||||||
-- NewlineFraming
|
-- NewlineFraming
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- | A simple framing strategy that has no header or termination, and inserts a
|
-- | A simple framing strategy that has no header, and inserts a
|
||||||
-- newline character between each frame. This assumes that it is used with a
|
-- newline character after each frame. This assumes that it is used with a
|
||||||
-- Content-Type that encodes without newlines (e.g. JSON).
|
-- Content-Type that encodes without newlines (e.g. JSON).
|
||||||
data NewlineFraming
|
data NewlineFraming
|
||||||
|
|
||||||
instance FramingRender NewlineFraming where
|
instance FramingRender NewlineFraming where
|
||||||
framingRender _ f = mapStepT go0 where
|
framingRender _ f = fmap (\x -> f x <> "\n")
|
||||||
go0 Stop = Stop
|
|
||||||
go0 (Error err) = Error err
|
|
||||||
go0 (Skip s) = Skip (go0 s)
|
|
||||||
go0 (Yield x s) = Yield (f x) (go s)
|
|
||||||
go0 (Effect ms) = Effect (fmap go0 ms)
|
|
||||||
|
|
||||||
go = fmap (\x -> "\n" <> f x)
|
|
||||||
|
|
||||||
instance FramingUnrender NewlineFraming where
|
instance FramingUnrender NewlineFraming where
|
||||||
framingUnrender _ f = transformWithAtto $ do
|
framingUnrender _ f = transformWithAtto $ do
|
||||||
|
|
|
@ -38,7 +38,7 @@ spec = describe "Servant.API.Stream" $ do
|
||||||
|
|
||||||
it "framingRender examples" $ do
|
it "framingRender examples" $ do
|
||||||
runRenderFrames re [] `shouldBe` Right ""
|
runRenderFrames re [] `shouldBe` Right ""
|
||||||
runRenderFrames re ["foo", "bar", "baz"] `shouldBe` Right "foo\nbar\nbaz"
|
runRenderFrames re ["foo", "bar", "baz"] `shouldBe` Right "foo\nbar\nbaz\n"
|
||||||
|
|
||||||
it "framingUnrender examples" $ do
|
it "framingUnrender examples" $ do
|
||||||
let expected n = map Right [fromString ("foo" ++ show (n :: Int)), "bar", "baz"]
|
let expected n = map Right [fromString ("foo" ++ show (n :: Int)), "bar", "baz"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue