wuss 1.1.16 → 1.1.17
raw patch · 8 files changed
+271/−310 lines, 8 filessetup-changed
Files
- CHANGELOG.markdown +0/−7
- README.markdown +5/−9
- Setup.hs +0/−4
- library/Wuss.hs +0/−217
- package.yaml +0/−36
- src/lib/Wuss.hs +217/−0
- stack.yaml +0/−1
- wuss.cabal +49/−36
− CHANGELOG.markdown
@@ -1,7 +0,0 @@-# Change log--Wuss uses [Semantic Versioning][].-The change log is available through the [releases on GitHub][].--[Semantic Versioning]: http://semver.org/spec/v2.0.0.html-[releases on GitHub]: https://github.com/tfausak/wuss/releases
README.markdown view
@@ -1,9 +1,10 @@-# [Wuss][]+# Wuss -Secure WebSocket (WSS) clients in Haskell.+[](https://travis-ci.org/tfausak/wuss)+[](https://hackage.haskell.org/package/wuss)+[](https://www.stackage.org/package/wuss) -[![Version badge][]][version]-[![Build badge][]][build]+Secure WebSocket (WSS) clients in Haskell. --- @@ -65,11 +66,6 @@ For more information about Wuss, please read [the Haddock documentation][]. -[Wuss]: http://taylor.fausak.me/wuss/-[Version badge]: https://www.stackage.org/package/wuss/badge/nightly?label=version-[version]: https://www.stackage.org/package/wuss-[Build badge]: https://travis-ci.org/tfausak/wuss.svg?branch=master-[build]: https://travis-ci.org/tfausak/wuss [the `websockets` package]: https://hackage.haskell.org/package/websockets [@jaspervdj]: https://gist.github.com/jaspervdj/7198388 [@mpickering]: https://gist.github.com/mpickering/f1b7ba3190a4bb5884f3
− Setup.hs
@@ -1,4 +0,0 @@-import qualified Distribution.Simple as Cabal--main :: IO ()-main = Cabal.defaultMain
− library/Wuss.hs
@@ -1,217 +0,0 @@-{-# LANGUAGE NoImplicitPrelude #-}--{- |- 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>.-- == Example-- > import Wuss- >- > import Control.Concurrent (forkIO)- > import Control.Monad (forever, unless, void)- > import Data.Text (Text, pack)- > import Network.WebSockets (ClientApp, receiveData, sendClose, sendTextData)- >- > main :: IO ()- > main = runSecureClient "echo.websocket.org" 443 "/" ws- >- > ws :: ClientApp ()- > ws connection = do- > putStrLn "Connected!"- >- > void . forkIO . forever $ do- > message <- receiveData connection- > print (message :: Text)- >- > let loop = do- > line <- getLine- > unless (null line) $ do- > sendTextData connection (pack line)- > loop- > loop- >- > sendClose connection (pack "Bye!")--}-module Wuss- ( runSecureClient- , runSecureClientWith- , Config(..)- , defaultConfig- , runSecureClientWithConfig- ) where--import qualified Control.Applicative as Applicative-import qualified Control.Exception as Exception-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-import qualified System.IO.Error as IO.Error---{- |- A secure replacement for 'Network.WebSockets.runClient'.-- >>> let app _connection = return ()- >>> runSecureClient "echo.websocket.org" 443 "/" app--}-runSecureClient- :: 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- runSecureClientWith host port path options [] app---{- |- A secure replacement for 'Network.WebSockets.runClientWith'.-- >>> let options = defaultConnectionOptions- >>> let headers = []- >>> let app _connection = return ()- >>> runSecureClientWith "echo.websocket.org" 443 "/" options headers app-- If you want to run a secure client without certificate validation, use- 'Network.WebSockets.runClientWithStream'. For example:-- > let host = "echo.websocket.org"- > let port = 443- > let path = "/"- > let options = defaultConnectionOptions- > let headers = []- > let tlsSettings = TLSSettingsSimple- > -- This is the important setting.- > { settingDisableCertificateValidation = True- > , settingDisableSession = False- > , settingUseServerName = False- > }- > let connectionParams = ConnectionParams- > { connectionHostname = host- > , connectionPort = port- > , connectionUseSecure = Just tlsSettings- > , connectionUseSocks = Nothing- > }- >- > context <- initConnectionContext- > connection <- connectTo context connectionParams- > stream <- makeStream- > (fmap Just (connectionGetChunk connection))- > (maybe (return ()) (connectionPut connection . toStrict))- > runClientWithStream stream host path options headers $ \ connection -> do- > -- Do something with the connection.- > return ()--}-runSecureClientWith- :: 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- let config = defaultConfig- runSecureClientWithConfig host port path config options headers app----- | 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'.- }----- | 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- Exception.bracket- (Connection.connectTo context (connectionParams host port))- Connection.connectionClose- (\connection -> do- 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 =- IO.Error.catchIOError (do- chunk <- (connectionGet config) connection- Applicative.pure (Maybe.Just chunk))- (\e ->- if IO.Error.isEOFError e- then Applicative.pure Maybe.Nothing- else Exception.throwIO e)---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
@@ -1,36 +0,0 @@-name: wuss-version: 1.1.16--category: Network-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>.-extra-source-files:- - CHANGELOG.markdown- - package.yaml- - README.markdown- - stack.yaml-github: tfausak/wuss-license-file: LICENSE.markdown-license: MIT-maintainer: Taylor Fausak-synopsis: Secure WebSocket (WSS) clients--dependencies:- base: '>= 4.9.0 && < 4.15'- bytestring: '>= 0.10.8 && < 0.11'- connection: '>= 0.2.6 && < 0.4'- network: '>= 2.6.3 && < 2.9 || >= 3.0.0 && < 3.2'- websockets: '>= 0.9.7 && < 0.13'-ghc-options:- -Weverything- -Wno-safe- -Wno-unsafe--library:- source-dirs: library
+ src/lib/Wuss.hs view
@@ -0,0 +1,217 @@+{-# LANGUAGE NoImplicitPrelude #-}++{- |+ 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>.++ == Example++ > import Wuss+ >+ > import Control.Concurrent (forkIO)+ > import Control.Monad (forever, unless, void)+ > import Data.Text (Text, pack)+ > import Network.WebSockets (ClientApp, receiveData, sendClose, sendTextData)+ >+ > main :: IO ()+ > main = runSecureClient "echo.websocket.org" 443 "/" ws+ >+ > ws :: ClientApp ()+ > ws connection = do+ > putStrLn "Connected!"+ >+ > void . forkIO . forever $ do+ > message <- receiveData connection+ > print (message :: Text)+ >+ > let loop = do+ > line <- getLine+ > unless (null line) $ do+ > sendTextData connection (pack line)+ > loop+ > loop+ >+ > sendClose connection (pack "Bye!")+-}+module Wuss+ ( runSecureClient+ , runSecureClientWith+ , Config(..)+ , defaultConfig+ , runSecureClientWithConfig+ ) where++import qualified Control.Applicative as Applicative+import qualified Control.Exception as Exception+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+import qualified System.IO.Error as IO.Error+++{- |+ A secure replacement for 'Network.WebSockets.runClient'.++ >>> let app _connection = return ()+ >>> runSecureClient "echo.websocket.org" 443 "/" app+-}+runSecureClient+ :: 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+ runSecureClientWith host port path options [] app+++{- |+ A secure replacement for 'Network.WebSockets.runClientWith'.++ >>> let options = defaultConnectionOptions+ >>> let headers = []+ >>> let app _connection = return ()+ >>> runSecureClientWith "echo.websocket.org" 443 "/" options headers app++ If you want to run a secure client without certificate validation, use+ 'Network.WebSockets.runClientWithStream'. For example:++ > let host = "echo.websocket.org"+ > let port = 443+ > let path = "/"+ > let options = defaultConnectionOptions+ > let headers = []+ > let tlsSettings = TLSSettingsSimple+ > -- This is the important setting.+ > { settingDisableCertificateValidation = True+ > , settingDisableSession = False+ > , settingUseServerName = False+ > }+ > let connectionParams = ConnectionParams+ > { connectionHostname = host+ > , connectionPort = port+ > , connectionUseSecure = Just tlsSettings+ > , connectionUseSocks = Nothing+ > }+ >+ > context <- initConnectionContext+ > connection <- connectTo context connectionParams+ > stream <- makeStream+ > (fmap Just (connectionGetChunk connection))+ > (maybe (return ()) (connectionPut connection . toStrict))+ > runClientWithStream stream host path options headers $ \ connection -> do+ > -- Do something with the connection.+ > return ()+-}+runSecureClientWith+ :: 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+ let config = defaultConfig+ runSecureClientWithConfig host port path config options headers app+++-- | 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'.+ }+++-- | 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+ Exception.bracket+ (Connection.connectTo context (connectionParams host port))+ Connection.connectionClose+ (\connection -> do+ 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 =+ IO.Error.catchIOError (do+ chunk <- (connectionGet config) connection+ Applicative.pure (Maybe.Just chunk))+ (\e ->+ if IO.Error.isEOFError e+ then Applicative.pure Maybe.Nothing+ else Exception.throwIO e)+++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)
− stack.yaml
@@ -1,1 +0,0 @@-resolver: lts-15.4
wuss.cabal view
@@ -1,44 +1,57 @@-cabal-version: 1.12+cabal-version: 2.2 --- This file has been generated from package.yaml by hpack version 0.33.0.------ see: https://github.com/sol/hpack------ hash: 87c6b73c3d1616afe6e62d21efc6b4da44a6e9860346ff17ccab540e558bbf3d+name: wuss+version: 1.1.17 -name: wuss-version: 1.1.16-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-homepage: https://github.com/tfausak/wuss#readme-bug-reports: https://github.com/tfausak/wuss/issues-maintainer: Taylor Fausak-license: MIT-license-file: LICENSE.markdown-build-type: Simple-extra-source-files:- CHANGELOG.markdown- package.yaml- README.markdown- stack.yaml+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>. +build-type: Simple+category: Network+extra-source-files: README.markdown+license-file: LICENSE.markdown+license: MIT+maintainer: Taylor Fausak+ source-repository head- type: git location: https://github.com/tfausak/wuss+ type: git +common basics+ default-language: Haskell2010+ ghc-options:+ -Weverything+ -Wno-all-missed-specialisations+ -Wno-implicit-prelude+ -Wno-missing-exported-signatures+ -Wno-missing-import-lists+ -Wno-safe+ -Wno-unsafe++ if impl(ghc >= 8.8)+ ghc-options:+ -Wno-missing-deriving-strategies++ if impl(ghc >= 8.10)+ ghc-options:+ -Wno-missing-safe-haskell-mode+ -Wno-prepositive-qualified-module+ library- exposed-modules:- Wuss- other-modules:- Paths_wuss- hs-source-dirs:- library- ghc-options: -Weverything -Wno-safe -Wno-unsafe+ import: basics+ build-depends:- base >=4.9.0 && <4.15- , bytestring >=0.10.8 && <0.11- , connection >=0.2.6 && <0.4- , network >=2.6.3 && <2.9 || >=3.0.0 && <3.2- , websockets >=0.9.7 && <0.13- default-language: Haskell2010+ base >= 4.9.0 && < 4.15+ , bytestring >= 0.10.8 && < 0.11+ , connection >= 0.2.6 && < 0.4+ , network >= 2.6.3 && < 2.9 || >= 3.0.0 && < 3.2+ , websockets >= 0.9.7 && < 0.13+ exposed-modules: Wuss+ hs-source-dirs: src/lib