add httpMethod param to httpclient.call

This commit is contained in:
andri lim 2018-11-13 10:22:43 +07:00
parent 06637848de
commit 3c4c5559f1

View File

@ -22,8 +22,8 @@ const
HeadersMark = @[byte(0x0D), byte(0x0A), byte(0x0D), byte(0x0A)]
proc sendRequest(transp: StreamTransport,
data: string, options: HttpClientOptions): Future[bool] {.async.} =
var request = $options.httpMethod & " / "
data: string, httpMethod: HttpMethod): Future[bool] {.async.} =
var request = $httpMethod & " / "
request.add($HttpVersion11)
request.add("\r\n")
request.add("Date: " & httpDate() & "\r\n")
@ -154,7 +154,7 @@ proc httpMethod*(client: RpcHttpClient, m: HttpMethod) =
client.options.httpMethod = m
proc call*(client: RpcHttpClient, name: string,
params: JsonNode): Future[Response] {.async.} =
params: JsonNode, httpMethod: HttpMethod): Future[Response] {.async.} =
## Remotely calls the specified RPC method.
let id = client.getNextId()
@ -162,7 +162,7 @@ proc call*(client: RpcHttpClient, name: string,
if isNil(client.transp) or client.transp.closed():
raise newException(ValueError,
"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:
debug "Failed to send message to RPC server",
address = client.transp.remoteAddress(), msg_len = res
@ -178,6 +178,10 @@ proc call*(client: RpcHttpClient, name: string,
client.awaiting[id] = newFut
result = await newFut
template call*(client: RpcHttpClient, name: string,
params: JsonNode): untyped =
client.call(name, params, client.httpMethod)
proc processData(client: RpcHttpClient) {.async.} =
while true:
var value = await client.transp.recvData()