packages feed

linnet-conduit 0.2.0.0 → 0.3.0.0

raw patch · 3 files changed

+20/−15 lines, 3 filesdep ~linnetPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: linnet

API changes (from Hackage documentation)

- Linnet.Conduit: instance (Linnet.Encode.Encode ct a, GHC.TypeLits.KnownSymbol ct, Linnet.NaturalTransformation.NaturalTransformation m GHC.Types.IO, Control.Monad.IO.Class.MonadIO m) => Linnet.ToResponse.ToResponse ct (Data.Conduit.Internal.Conduit.ConduitT () a m ())
+ Linnet.Conduit: instance (Linnet.Encode.Encode (Data.Proxy.Proxy ct) a, GHC.TypeLits.KnownSymbol ct, Linnet.NaturalTransformation.NaturalTransformation m GHC.Types.IO, Control.Monad.IO.Class.MonadIO m) => Linnet.ToResponse.ToResponse (Data.Proxy.Proxy ct) (Data.Conduit.Internal.Conduit.ConduitT () a m ())

Files

linnet-conduit.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: linnet-conduit-version: 0.2.0.0+version: 0.3.0.0 license: Apache license-file: LICENSE copyright: 2019 Sergey Kolbasov@@ -33,7 +33,7 @@         bytestring >=0.10.8.2,         conduit >=1.3.1.1,         http-types >=0.12.3,-        linnet >=0.2.0.0,+        linnet >=0.3.0.0,         wai >=3.2.2.1,         warp >=3.2.28 @@ -53,7 +53,7 @@         conduit >=1.3.1.1,         hspec >=2.7.1,         http-types >=0.12.3,-        linnet >=0.2.0.0,+        linnet >=0.3.0.0,         linnet-conduit -any,         quickcheck-classes >=0.6.1.0,         quickcheck-instances >=0.3.22,
src/Linnet/Conduit.hs view
@@ -33,7 +33,7 @@ import           Data.Void                    (Void) import           GHC.TypeLits                 (KnownSymbol, symbolVal) import           Linnet-import           Linnet.Endpoint              (EndpointResult (..))+import           Linnet.Endpoint              (EndpointResult (..), NotMatchedReason(..)) import           Linnet.Input                 (request) import           Linnet.NaturalTransformation (NaturalTransformation (..)) import           Linnet.ToResponse@@ -67,24 +67,24 @@                         do liftIO $ pauseTimeout req                            pure $ ok $ (fromLazyBody . lazyRequestBody) req                     }-                KnownLength _ -> NotMatched+                KnownLength _ -> NotMatched Other     , toString = "streamBody"     }  instance {-# OVERLAPS #-} (Encode ApplicationJson a, NaturalTransformation m IO, MonadIO m) =>                           ToResponse ApplicationJson (ConduitT () a m ()) where-  toResponse stream =-    responseStream status200 [("Content-Type", "application/json")] $ \write flush ->+  toResponse status headers stream =+    responseStream status (("Content-Type", "application/json") : headers) $ \write flush ->       let push :: ConduitT a Void m ()           push =             mapM_C               (\chunk -> liftIO $ write (Builder.lazyByteString (encode @ApplicationJson chunk)) >> write "\n" >> flush)        in mapK (runConduit $ stream .| push) -instance {-# OVERLAPS #-} (Encode ct a, KnownSymbol ct, NaturalTransformation m IO, MonadIO m) =>-                          ToResponse ct (ConduitT () a m ()) where-  toResponse stream =-    responseStream status200 [("Content-Type", C8.pack $ symbolVal (Proxy :: Proxy ct))] $ \write flush ->+instance {-# OVERLAPS #-} (Encode (Proxy ct) a, KnownSymbol ct, NaturalTransformation m IO, MonadIO m) =>+                          ToResponse (Proxy ct) (ConduitT () a m ()) where+  toResponse status headers stream =+    responseStream status (("Content-Type", C8.pack $ symbolVal (Proxy :: Proxy ct)) : headers) $ \write flush ->       let push :: ConduitT a Void m ()-          push = mapM_C (\chunk -> liftIO $ write (Builder.lazyByteString (encode @ct chunk)) >> flush)+          push = mapM_C (\chunk -> liftIO $ write (Builder.lazyByteString (encode @(Proxy ct) chunk)) >> flush)        in mapK (runConduit $ stream .| push)
test/ConduitSpec.hs view
@@ -23,6 +23,7 @@                                             runEndpoint) import           Linnet.Input import           Linnet.ToResponse+import           Network.HTTP.Types.Status (ok200) import           Network.Wai               (RequestBodyLength (..),                                             defaultRequest, requestBody,                                             requestBodyLength, responseStream,@@ -65,7 +66,7 @@            in monadicIO $ do                 final <- liftIO $ newIORef ([] @BS.ByteString)                 buffer <- liftIO $ newIORef ([] @BS.ByteString)-                let response = toResponse @TextPlain $ stream bytes+                let response = toResponse @TextPlain ok200 [] $ stream bytes                 let (_, _, responseBody) = responseToStream response                 let write builder = modifyIORef buffer (++ [BL.toStrict $ Builder.toLazyByteString builder])                 let flush = do@@ -82,7 +83,7 @@            in monadicIO $ do                 final <- liftIO $ newIORef ([] @BS.ByteString)                 buffer <- liftIO $ newIORef ([] @BS.ByteString)-                let response = toResponse @ApplicationJson $ stream bytes+                let response = toResponse @ApplicationJson ok200 [] $ stream bytes                 let (_, _, responseBody) = responseToStream response                 let write builder = modifyIORef buffer (++ [BL.toStrict $ Builder.toLazyByteString builder])                 let flush = do@@ -91,7 +92,11 @@                       _ <- modifyIORef buffer (const [])                       return ()                 result <- liftIO $ responseBody (\fn -> fn write flush >> readIORef final)-                assert (result == if null bytes then [] else intersperse "\n" bytes ++ ["\n"])+                assert+                  (result ==+                   if null bytes+                     then []+                     else intersperse "\n" bytes ++ ["\n"])  instance Encode ApplicationJson BS.ByteString where   encode = BL.fromStrict