packages feed

wuss 1.0.4 → 1.1.0

raw patch · 4 files changed

+114/−51 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Wuss: Config :: (Connection -> IO ByteString) -> Config
+ Wuss: [connectionGet] :: Config -> Connection -> IO ByteString
+ Wuss: data Config
+ Wuss: defaultConfig :: Config
+ Wuss: runSecureClientWithConfig :: HostName -> PortNumber -> String -> Config -> ConnectionOptions -> Headers -> ClientApp a -> IO a

Files

Wuss.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE NoImplicitPrelude #-}+ {- |     Wuss is a library that lets you easily create secure WebSocket clients over     the WSS protocol. It is a small addition to@@ -39,18 +41,24 @@ module Wuss     ( runSecureClient     , runSecureClientWith+    , Config(..)+    , defaultConfig+    , runSecureClientWithConfig     ) where -import qualified Data.ByteString as BS-import Data.ByteString.Lazy (toStrict)-import qualified Data.ByteString.Lazy as BL-import Network.Connection (Connection, ConnectionParams (..), TLSSettings (..),-    connectTo, connectionGetChunk, connectionPut, initConnectionContext)-import Network.Socket (HostName, PortNumber)-import Network.WebSockets (ClientApp, ConnectionOptions, Headers,-    defaultConnectionOptions, runClientWithStream)-import Network.WebSockets.Stream (makeStream)+import qualified Control.Applicative as Applicative+import qualified Data.Bool as Bool+import qualified Data.ByteString as StrictBytes+import qualified Data.ByteString.Lazy as LazyBytes+import qualified Data.Maybe as Maybe+import qualified Data.String as String+import qualified Network.Connection as Connection+import qualified Network.Socket as Socket+import qualified Network.WebSockets as WebSockets+import qualified Network.WebSockets.Stream as Stream+import qualified System.IO as IO + {- |     A secure replacement for 'Network.WebSockets.runClient'. @@ -58,16 +66,17 @@     >>> runSecureClient "echo.websocket.org" 443 "/" app -} runSecureClient-    :: HostName -- ^ Host-    -> PortNumber -- ^ Port-    -> String -- ^ Path-    -> ClientApp a -- ^ Application-    -> IO a-runSecureClient host port path app =-    let options = defaultConnectionOptions-        headers = []-    in  runSecureClientWith host port path options headers app+    :: Socket.HostName -- ^ Host+    -> Socket.PortNumber -- ^ Port+    -> String.String -- ^ Path+    -> WebSockets.ClientApp a -- ^ Application+    -> IO.IO a+runSecureClient host port path app = do+    let options = WebSockets.defaultConnectionOptions+    let headers = []+    runSecureClientWith host port path options headers app + {- |     A secure replacement for 'Network.WebSockets.runClientWith'. @@ -107,36 +116,92 @@     >     return () -} runSecureClientWith-    :: HostName -- ^ Host-    -> PortNumber -- ^ Port-    -> String -- ^ Path-    -> ConnectionOptions -- ^ Options-    -> Headers -- ^ Headers-    -> ClientApp a -- ^ Application-    -> IO a+    :: Socket.HostName -- ^ Host+    -> Socket.PortNumber -- ^ Port+    -> String.String -- ^ Path+    -> WebSockets.ConnectionOptions -- ^ Options+    -> WebSockets.Headers -- ^ Headers+    -> WebSockets.ClientApp a -- ^ Application+    -> IO.IO a runSecureClientWith host port path options headers app = do-    context <- initConnectionContext-    connection <- connectTo context (connectionParams host port)-    stream <- makeStream (reader connection) (writer connection)-    runClientWithStream stream host path options headers app+    let config = defaultConfig+    runSecureClientWithConfig host port path config options headers app -connectionParams :: HostName -> PortNumber -> ConnectionParams-connectionParams host port = ConnectionParams-    { connectionHostname = host-    , connectionPort = port-    , connectionUseSecure = Just tlsSettings-    , connectionUseSocks = Nothing-    } -tlsSettings :: TLSSettings-tlsSettings = TLSSettingsSimple-    { settingDisableCertificateValidation = False-    , settingDisableSession = False-    , settingUseServerName = False+-- | Configures a secure WebSocket connection.+data Config = Config+    { connectionGet :: Connection.Connection -> IO.IO StrictBytes.ByteString+    -- ^ How to get bytes from the connection. Typically+    -- 'Connection.connectionGetChunk', but could be something else like+    -- 'Connection.connectionGetLine'.     } -reader :: Connection -> IO (Maybe BS.ByteString)-reader connection = fmap Just (connectionGetChunk connection) -writer :: Connection -> Maybe BL.ByteString -> IO ()-writer connection = maybe (return ()) (connectionPut connection . toStrict)+-- | The default 'Config' value used by 'runSecureClientWith'.+defaultConfig+    :: Config+defaultConfig = do+    Config+        { connectionGet = Connection.connectionGetChunk+        }+++-- | Runs a secure WebSockets client with the given 'Config'.+runSecureClientWithConfig+    :: Socket.HostName -- ^ Host+    -> Socket.PortNumber -- ^ Port+    -> String.String -- ^ Path+    -> Config -- ^ Config+    -> WebSockets.ConnectionOptions -- ^ Options+    -> WebSockets.Headers -- ^ Headers+    -> WebSockets.ClientApp a -- ^ Application+    -> IO.IO a+runSecureClientWithConfig host port path config options headers app = do+    context <- Connection.initConnectionContext+    connection <- Connection.connectTo context (connectionParams host port)+    stream <- Stream.makeStream (reader config connection) (writer connection)+    WebSockets.runClientWithStream stream host path options headers app+++connectionParams+    :: Socket.HostName+    -> Socket.PortNumber+    -> Connection.ConnectionParams+connectionParams host port = do+    Connection.ConnectionParams+        { Connection.connectionHostname = host+        , Connection.connectionPort = port+        , Connection.connectionUseSecure = Maybe.Just tlsSettings+        , Connection.connectionUseSocks = Maybe.Nothing+        }+++tlsSettings+    :: Connection.TLSSettings+tlsSettings = do+    Connection.TLSSettingsSimple+        { Connection.settingDisableCertificateValidation = Bool.False+        , Connection.settingDisableSession = Bool.False+        , Connection.settingUseServerName = Bool.False+        }+++reader+    :: Config+    -> Connection.Connection+    -> IO.IO (Maybe.Maybe StrictBytes.ByteString)+reader config connection = do+    chunk <- (connectionGet config) connection+    Applicative.pure (Maybe.Just chunk)+++writer+    :: Connection.Connection+    -> Maybe.Maybe LazyBytes.ByteString+    -> IO.IO ()+writer connection maybeBytes = do+    case maybeBytes of+        Maybe.Nothing -> do+            Applicative.pure ()+        Maybe.Just bytes -> do+            Connection.connectionPut connection (LazyBytes.toStrict bytes)
package.yaml view
@@ -25,4 +25,4 @@ maintainer: Taylor Fausak name: wuss synopsis: Secure WebSocket (WSS) clients-version: '1.0.4'+version: '1.1.0'
stack.yaml view
@@ -1,3 +1,1 @@-install-ghc: true-require-stack-version: ! '>=1.0.4'-resolver: lts-5.12+resolver: nightly-2016-07-05
wuss.cabal view
@@ -1,9 +1,9 @@--- This file has been generated from package.yaml by hpack version 0.9.0.+-- This file has been generated from package.yaml by hpack version 0.14.0. -- -- see: https://github.com/sol/hpack  name:           wuss-version:        1.0.4+version:        1.1.0 synopsis:       Secure WebSocket (WSS) clients description:    Wuss is a library that lets you easily create secure WebSocket clients over the WSS protocol. It is a small addition to <https://hackage.haskell.org/package/websockets the websockets package> and is adapted from existing solutions by <https://gist.github.com/jaspervdj/7198388 @jaspervdj>, <https://gist.github.com/mpickering/f1b7ba3190a4bb5884f3 @mpickering>, and <https://gist.github.com/elfenlaid/7b5c28065e67e4cf0767 @elfenlaid>. category:       Network