mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-01-08 16:43:10 +00:00
add httpMethod param to httpclient.call
This commit is contained in:
parent
06637848de
commit
3c4c5559f1
@ -22,8 +22,8 @@ const
|
|||||||
HeadersMark = @[byte(0x0D), byte(0x0A), byte(0x0D), byte(0x0A)]
|
HeadersMark = @[byte(0x0D), byte(0x0A), byte(0x0D), byte(0x0A)]
|
||||||
|
|
||||||
proc sendRequest(transp: StreamTransport,
|
proc sendRequest(transp: StreamTransport,
|
||||||
data: string, options: HttpClientOptions): Future[bool] {.async.} =
|
data: string, httpMethod: HttpMethod): Future[bool] {.async.} =
|
||||||
var request = $options.httpMethod & " / "
|
var request = $httpMethod & " / "
|
||||||
request.add($HttpVersion11)
|
request.add($HttpVersion11)
|
||||||
request.add("\r\n")
|
request.add("\r\n")
|
||||||
request.add("Date: " & httpDate() & "\r\n")
|
request.add("Date: " & httpDate() & "\r\n")
|
||||||
@ -154,7 +154,7 @@ proc httpMethod*(client: RpcHttpClient, m: HttpMethod) =
|
|||||||
client.options.httpMethod = m
|
client.options.httpMethod = m
|
||||||
|
|
||||||
proc call*(client: RpcHttpClient, name: string,
|
proc call*(client: RpcHttpClient, name: string,
|
||||||
params: JsonNode): Future[Response] {.async.} =
|
params: JsonNode, httpMethod: HttpMethod): Future[Response] {.async.} =
|
||||||
## Remotely calls the specified RPC method.
|
## Remotely calls the specified RPC method.
|
||||||
let id = client.getNextId()
|
let id = client.getNextId()
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ proc call*(client: RpcHttpClient, name: string,
|
|||||||
if isNil(client.transp) or client.transp.closed():
|
if isNil(client.transp) or client.transp.closed():
|
||||||
raise newException(ValueError,
|
raise newException(ValueError,
|
||||||
"Transport is not initialised or already closed")
|
"Transport is not initialised or already closed")
|
||||||
let res = await client.transp.sendRequest(value, client.options)
|
let res = await client.transp.sendRequest(value, httpMethod)
|
||||||
if not res:
|
if not res:
|
||||||
debug "Failed to send message to RPC server",
|
debug "Failed to send message to RPC server",
|
||||||
address = client.transp.remoteAddress(), msg_len = res
|
address = client.transp.remoteAddress(), msg_len = res
|
||||||
@ -178,6 +178,10 @@ proc call*(client: RpcHttpClient, name: string,
|
|||||||
client.awaiting[id] = newFut
|
client.awaiting[id] = newFut
|
||||||
result = await newFut
|
result = await newFut
|
||||||
|
|
||||||
|
template call*(client: RpcHttpClient, name: string,
|
||||||
|
params: JsonNode): untyped =
|
||||||
|
client.call(name, params, client.httpMethod)
|
||||||
|
|
||||||
proc processData(client: RpcHttpClient) {.async.} =
|
proc processData(client: RpcHttpClient) {.async.} =
|
||||||
while true:
|
while true:
|
||||||
var value = await client.transp.recvData()
|
var value = await client.transp.recvData()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user