From 07e82fa19499d10012c9d125a61ac565a01e3305 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Wed, 31 Jul 2019 12:04:53 +0300 Subject: [PATCH] Allow creating http client from url --- json_rpc/clients/httpclient.nim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/json_rpc/clients/httpclient.nim b/json_rpc/clients/httpclient.nim index eb90256..f07d654 100644 --- a/json_rpc/clients/httpclient.nim +++ b/json_rpc/clients/httpclient.nim @@ -1,4 +1,4 @@ -import json, strutils, tables +import json, strutils, tables, uri import chronicles, httputils, chronos, json_serialization/std/net import ../client @@ -204,3 +204,11 @@ method call*(client: RpcHttpClient, name: string, proc connect*(client: RpcHttpClient, address: string, port: Port) {.async.} = client.addresses = resolveTAddress(address, port) + +proc connect*(client: RpcHttpClient, url: string) {.async.} = + # TODO: The url (path, etc) should make it into the request + let pu = parseUri(url) + var port = Port(80) + if pu.port.len != 0: + port = parseInt(pu.port).Port + client.addresses = resolveTAddress(pu.hostname, port)