Merge pull request #61 from status-im/custom-headers

Allow custom headers in ws backend. Set Origin to http://localhost by default
This commit is contained in:
Yuriy Glukhov 2019-07-17 13:07:04 +03:00 committed by GitHub
commit 3b02cbd946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

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)