Run secure WebSocket clients with Wuss
While working on pressing the button with Haskell, I needed to establish a
secure WebSocket (WSS) connection. Unfortunately the existing websockets
package did not support secure WebSockets. I looked around and found an
issue addressing it. It had a few workarounds by @jaspervdj,
@mpickering, and @elfenlaid. 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.
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. 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