HTTP.jl Websockets- help getting started

Thanks for the input. I dug through the source a little and came up with this:

function rawws(url,headers =[])
    headers = [
        "Upgrade" => "websocket",
        "Connection" => "Upgrade",
        "Sec-WebSocket-Key" => base64encode(rand(Random.RandomDevice(), UInt8, 16)),
        "Sec-WebSocket-Version" => "13",
        headers...
    ]
    r = HTTP.openraw("GET",url,headers)[1]

    ws = WebSockets.WebSocket(r)
    return ws
end

This is just constructed from parts and pieces of the HTTP.jl package and essentially gives a raw web socket that you have to manage manually. I’m using this with SurrealDB and so far it is working well. I see the intent and benefit of having the full lifecycle of the WS managed and ensuring that it is closed, but also having a persistent socket has been handy for prototyping and troubleshooting.

I’d love to make this available for anyone else who might find it useful, but I’m not sure of a few things:

  1. Is this a reasonable solution? (Works for me, but does it make sense beyond my use case?)
  2. If yes, I don’t know how to submit a PR, but willing to learn. Any resources for a newbie?
2 Likes