Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (30 sloc) 1.59 KB
Run secure WebSocket clients with Wuss

While working on [pressing the button with Haskell][1], I needed to establish a secure WebSocket (WSS) connection. Unfortunately the existing [websockets package][2] did not support secure WebSockets. I looked around and found [an issue][3] addressing it. It had a few workarounds by [@jaspervdj][4], [@mpickering][5], and [@elfenlaid][6]. They got the job done, but weren't nearly as easy to use as the insecure runClient function. I figured that other people could benefit from having a turnkey WSS solution, so I packaged it up and released it as [Wuss][7].

I was surprised by how easy it was to add support for secure clients to the websockets package. It only took [five lines of code][8]. That is a testament to the design of that package, the strength of the ecosystem, and the expressiveness of Haskell as a language.

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

[1]: {% post_url 2015-04-23-pressing-the-button-with-haskell %} [2]: [3]: [4]: [5]: [6]: [7]: [8]: