packages feed

http-client-websockets 0.1.1.2 → 0.1.1.3

raw patch · 4 files changed

+45/−16 lines, 4 filesdep +asyncdep −http-client-tlsdep ~http-clientPVP ok

version bump matches the API change (PVP)

Dependencies added: async

Dependencies removed: http-client-tls

Dependency ranges changed: http-client

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for http-client-websockets +## 0.1.1.3 -- 2022-08-16++* Remove test dependency on http-client-websockets.+* New echo server in Haddocks.+ ## 0.1.1.2 -- 2021-05-29  * Remove dependency on utf8-string.
http-client-websockets.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: http-client-websockets-version: 0.1.1.2+version: 0.1.1.3  synopsis: Glue code for http-client and websockets description:@@ -55,6 +55,7 @@     , bytestring     , hspec >= 2.5     , network-uri-    , http-client-tls+    , http-client     , websockets+    , async ^>= 2.2     , http-client-websockets
src/Network/HTTP/Client/WebSockets.hs view
@@ -14,7 +14,7 @@ --   >>> :set -XOverloadedStrings --   >>> :set -XQuasiQuotes --   >>>---   >>> import Network.HTTP.Client (Manager, defaultManagerSettings)+--   >>> import Network.HTTP.Client (Manager, defaultManagerSettings, newManager) --   >>> import qualified Network.WebSockets as WS --   >>> import qualified Network.HTTP.Client.WebSockets as HCWS --   >>> import Network.URI.Static@@ -24,14 +24,14 @@ --       runEchoExample :: Manager -> IO ByteString --       runEchoExample mgr = HCWS.runClient mgr echoUri $ \conn -> do --           WS.sendTextData conn ("hello there" :: ByteString)+--           _ <- WS.receiveDataMessage conn -- skip first msg --           msg <- WS.receiveData conn --           pure (msg :: ByteString) --         where---           echoUri = [uri|wss://echo.websocket.org|]+--           echoUri = [uri|ws://echo.websocket.events|] -- no TLS in this example --   :} -----   >>> import Network.HTTP.Client.TLS (newTlsManager)---   >>> newTlsManager >>= runEchoExample+--   >>> runEchoExample =<< newManager defaultManagerSettings --   "hello there" module Network.HTTP.Client.WebSockets   ( runClient,
test/Spec.hs view
@@ -3,10 +3,13 @@  module Main (main) where +import Control.Concurrent (threadDelay)+import Control.Concurrent.Async (withAsync)+import Control.Monad import Data.ByteString-import Data.Foldable (for_)-import Network.HTTP.Client.TLS (newTlsManager)-import Network.HTTP.Client.WebSockets as HCWS+import Data.IORef+import qualified Network.HTTP.Client as HC+import qualified Network.HTTP.Client.WebSockets as HCWS import Network.URI.Static import qualified Network.WebSockets as WS import Test.Hspec@@ -15,10 +18,30 @@ main = hspec $   describe "WebSockets via http-client" $ do     it "should connect to an echo server" $ do-      mgr <- newTlsManager-      for_ [[uri|ws://echo.websocket.org|], [uri|wss://echo.websocket.org|]] $ \u ->-        HCWS.runClient mgr u $ \conn -> do-          let bs = "test" :: ByteString-          WS.sendTextData conn bs-          bs' <- WS.receiveData conn-          bs `shouldBe` bs'+      pseudoTlsRef <- newIORef False+      mgr <-+        HC.newManager+          HC.defaultManagerSettings+            { HC.managerTlsConnection = do+                mkRawConnection <- HC.managerRawConnection HC.defaultManagerSettings+                pure $ \mha h p -> do+                  writeIORef pseudoTlsRef True+                  mkRawConnection mha h p+            }+      withEchoServer $ do+        HCWS.runClient mgr [uri|ws://localhost:12345|] testApp+        (`shouldBe` False) =<< readIORef pseudoTlsRef+        HCWS.runClient mgr [uri|wss://localhost:12345|] testApp+        (`shouldBe` True) =<< readIORef pseudoTlsRef+  where+    testApp conn = do+      let bs = "test" :: ByteString+      WS.sendTextData conn bs+      bs' <- WS.receiveData conn+      bs `shouldBe` bs'++    withEchoServer ma = withAsync runEchoServer (const $ threadDelay 100000 *> ma)+      where+        runEchoServer = WS.runServer "localhost" 12345 $ \pendingConn -> do+          conn <- WS.acceptRequest pendingConn+          forever $ WS.receive conn >>= WS.send conn