packages feed

wuss (empty) → 1.0.0

raw patch · 7 files changed

+237/−0 lines, 7 filesdep +basedep +bytestringdep +connectionsetup-changed

Dependencies added: base, bytestring, connection, doctest, network, websockets, wuss

Files

+ CHANGELOG.md view
@@ -0,0 +1,9 @@+# Change log++## v1.0.0 (2015-04-15)++-   Initially released.++## v0.0.0 (2015-04-15)++-   Initially created.
+ LICENSE.md view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2015 Taylor Fausak <taylor@fausak.me>++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ README.md view
@@ -0,0 +1,77 @@+<h1 align="center">+    <a href="http://taylor.fausak.me/wuss/">+        Wuss+    </a>+</h1>++<p align="center">+    Secure WebSocket (WSS) clients in Haskell.+</p>++<p align="center">+    <a href="https://hackage.haskell.org/package/wuss"><img alt="Version" src="https://img.shields.io/hackage/v/wuss.svg?label=version&amp;style=flat-square"></a>+    <a href="https://travis-ci.org/tfausak/wuss"><img alt="Build" src="https://img.shields.io/travis/tfausak/wuss/master.svg?label=build&amp;style=flat-square"></a>+    <a href="http://packdeps.haskellers.com/feed?needle=wuss"><img alt="Dependencies" src="https://img.shields.io/hackage-deps/v/wuss.svg?label=dependencies&amp;style=flat-square"></a>+</p>++<hr>++Wuss is a library that lets you easily create secure WebSocket clients over the+WSS protocol.++-   [Installation](#installation)+-   [Usage](#usage)++## Installation++To add Wuss as a dependency to your package, add it to your Cabal file.++```+build-depends: wuss ==1.*+```++For other use cases, install it with Cabal.++``` sh+$ cabal install 'wuss ==1.*'+```++Wuss uses [Semantic Versioning][]. See [the change log][] for a detailed list+of changes.++## Usage++``` hs+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!")+```++For more information about Wuss, please read [the Haddock documentation][].++[semantic versioning]: http://semver.org/spec/v2.0.0.html+[the change log]: CHANGELOG.md+[the haddock documentation]: https://hackage.haskell.org/package/wuss
+ Setup.hs view
@@ -0,0 +1,6 @@+module Main (main) where++import Distribution.Simple (defaultMain)++main :: IO ()+main = defaultMain
+ Wuss.hs view
@@ -0,0 +1,70 @@+module Wuss+    ( runSecureClient+    , runSecureClientWith+    ) 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)++{- |+    >>> let app _connection = return ()+    >>> 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++{- |+    >>> let options = defaultConnectionOptions+    >>> let headers = []+    >>> let app _connection = return ()+    >>> runSecureClientWith "echo.websocket.org" 443 "/" options headers app+-}+runSecureClientWith+    :: HostName -- ^ Host+    -> PortNumber -- ^ Port+    -> String -- ^ Path+    -> ConnectionOptions -- ^ Options+    -> Headers -- ^ Headers+    -> ClientApp a -- ^ Application+    -> 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++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+    }++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)
+ WussTest.hs view
@@ -0,0 +1,6 @@+module Main (main) where++import Test.DocTest (doctest)++main :: IO ()+main = doctest ["Wuss.hs"]
+ wuss.cabal view
@@ -0,0 +1,48 @@+name: wuss+version: 1.0.0+cabal-version: >=1.10+build-type: Simple+license: MIT+license-file: LICENSE.md+copyright: 2015 Taylor Fausak <taylor@fausak.me>+maintainer: Taylor Fausak <taylor@fausak.me>+homepage: http://taylor.fausak.me/wuss/+bug-reports: https://github.com/tfausak/wuss/issues+synopsis: Secure WebSocket (WSS) clients+description:+    Wuss is a library that lets you easily create secure WebSocket clients over+    the WSS protocol.+    .+    Please read <https://github.com/tfausak/wuss#readme the readme> for example+    usage.+category: Network+author: Taylor Fausak <taylor@fausak.me>+extra-source-files:+    CHANGELOG.md+    README.md++source-repository head+    type: git+    location: https://github.com/tfausak/wuss++library+    exposed-modules:+        Wuss+    build-depends:+        base ==4.*,+        bytestring -any,+        connection ==0.2.*,+        network -any,+        websockets ==0.9.*+    default-language: Haskell2010+    ghc-options: -Wall++test-suite test+    type: exitcode-stdio-1.0+    main-is: WussTest.hs+    build-depends:+        base -any,+        doctest ==0.9.*,+        wuss -any+    default-language: Haskell2010+    ghc-options: -Wall -Werror