From 64dbf122d7457ceabdacfb26131e929f26f15581 Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Thu, 22 Sep 2022 10:58:19 +0200 Subject: [PATCH] Add authhooks to proxy constructor (#153) --- json_rpc/rpcproxy.nim | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/json_rpc/rpcproxy.nim b/json_rpc/rpcproxy.nim index f4a03bd..12395d7 100644 --- a/json_rpc/rpcproxy.nim +++ b/json_rpc/rpcproxy.nim @@ -48,7 +48,7 @@ proc proxyCall(client: RpcClient, name: string): RpcProc = let res = await client.call(name, params) return StringOfJson($res) -proc getClient(proxy: RpcProxy): RpcClient = +proc getClient*(proxy: RpcProxy): RpcClient = case proxy.kind of Http: proxy.httpClient @@ -71,11 +71,20 @@ proc new*(T: type RpcProxy, server: RpcHttpServer, cfg: ClientConfig): T = flags: cfg.flags ) -proc new*(T: type RpcProxy, listenAddresses: openArray[TransportAddress], cfg: ClientConfig): T {.raises: [Defect, CatchableError].} = - RpcProxy.new(newRpcHttpServer(listenAddresses, RpcRouter.init()), cfg) +proc new*( + T: type RpcProxy, + listenAddresses: openArray[TransportAddress], + cfg: ClientConfig, + authHooks: seq[HttpAuthHook] = @[] +): T {.raises: [Defect, CatchableError].} = + RpcProxy.new(newRpcHttpServer(listenAddresses, RpcRouter.init(), authHooks), cfg) -proc new*(T: type RpcProxy, listenAddresses: openArray[string], cfg: ClientConfig): T {.raises: [Defect, CatchableError].} = - RpcProxy.new(newRpcHttpServer(listenAddresses, RpcRouter.init()), cfg) +proc new*( + T: type RpcProxy, + listenAddresses: openArray[string], + cfg: ClientConfig, + authHooks: seq[HttpAuthHook] = @[]): T {.raises: [Defect, CatchableError].} = + RpcProxy.new(newRpcHttpServer(listenAddresses, RpcRouter.init(), authHooks), cfg) proc connectToProxy(proxy: RpcProxy): Future[void] = case proxy.kind