Open Grobycn opened 4 years ago
I don't really understand what you mean here. The way I'm thinking about this, the headers are read prior to upgrading a connection to a websocket connection. While the websocket is open, any further communication on that connection will be interpreted as websocket communication.
So I suppose you actually mean 'have the ability of adding additional headers in the opening handshake'. I think you have that option. I might be wrong. Do you have a halfway-working example?
Sorry for my poor english. But yes, that's what I mean: have the ability of adding additional headers in the opening handshake.
Yes, adding this header could 'easily' be achieved by adding additional headers through the function call. But it complicates the API. For the user to be aware of which headers is missing requires detail knowledge, or at least a decent ability to study error messages. How did error messages look in your case? I hope they were informative.
Personally I think writing a custom 'open' function has more appeal than studying the nitty gritty of keyword arguments. It could be something like this:
module Grobycn
using WebSockets
import WebSockets.HTTP._openstream
import WebSockets.HTTP.open
import WebSockets.HTTP.IOExtras.IOError
function open_golang(f::Function, url; verbose=false, subprotocol = "", kw...)
key = base64encode(rand(UInt8, 16))
headers = [
"Upgrade" => "websocket",
"Connection" => "Upgrade",
"Sec-WebSocket-Key" => key,
"Sec-WebSocket-Version" => "13",
"Origin" => "xxxx"
]
....the rest a copy of WebSockets' 'open' function.
end
Some websocket server may check the headers, such as the example of
golang.org/x/net/websocket
. Get 403 when there is no "Origin: xxx" header.For compatibility, it shoud have the ability of adding additional headers to open websocket.