Allow custom headers in ws backend. Set Origin to http://localhost by default

This commit is contained in:
Yuriy Glukhov 2019-07-02 16:15:41 +03:00
parent af33cb9fbc
commit 881c62ed54

View File

@ -45,8 +45,15 @@ proc processData(client: RpcWebSocketClient) {.async.} =
# async loop reconnection and waiting
client.transport = await newWebSocket(client.uri)
proc connect*(client: RpcWebSocketClient, uri: string) {.async.} =
client.transport = await newWebSocket(uri)
proc connect*(client: RpcWebSocketClient, uri: string, headers: StringTableRef = nil) {.async.} =
var headers = headers
if headers.isNil:
headers = newStringTable({"Origin": "http://localhost"})
elif "Origin" notin headers:
# TODO: This is a hack, because the table might be case sensitive. Ideally strtabs module has
# to be extended with case insensitive accessors.
headers["Origin"] = "http://localhost"
client.transport = await newWebSocket(uri, headers)
client.uri = uri
client.loop = processData(client)