mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-01-07 16:13:07 +00:00
support Content-Type headers with specified charset
and add RPC message content to the debugging output (at the TRACE level, disabled by default)
This commit is contained in:
parent
756ad70598
commit
1083b2972a
@ -52,7 +52,8 @@ proc validateResponse*(transp: StreamTransport,
|
|||||||
return
|
return
|
||||||
|
|
||||||
var ctype = header["Content-Type"]
|
var ctype = header["Content-Type"]
|
||||||
if ctype.toLowerAscii() != "application/json":
|
# might be "application/json; charset=utf-8"
|
||||||
|
if "application/json" notin ctype.toLowerAscii():
|
||||||
# Content-Type header is not "application/json"
|
# Content-Type header is not "application/json"
|
||||||
debug "Content type must be application/json",
|
debug "Content type must be application/json",
|
||||||
address = transp.remoteAddress()
|
address = transp.remoteAddress()
|
||||||
@ -186,12 +187,13 @@ proc call*(client: RpcHttpClient, name: string,
|
|||||||
let res = await client.transp.sendRequest(value, httpMethod)
|
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 = len(value)
|
||||||
client.transp.close()
|
client.transp.close()
|
||||||
raise newException(ValueError, "Transport error")
|
raise newException(ValueError, "Transport error")
|
||||||
else:
|
else:
|
||||||
debug "Message sent to RPC server", address = client.transp.remoteAddress(),
|
debug "Message sent to RPC server", address = client.transp.remoteAddress(),
|
||||||
msg_len = res
|
msg_len = len(value)
|
||||||
|
trace "Message", msg = value
|
||||||
|
|
||||||
# completed by processMessage.
|
# completed by processMessage.
|
||||||
var newFut = newFuture[Response]()
|
var newFut = newFuture[Response]()
|
||||||
@ -211,6 +213,7 @@ proc processData(client: RpcHttpClient) {.async.} =
|
|||||||
debug "Received response from RPC server",
|
debug "Received response from RPC server",
|
||||||
address = client.transp.remoteAddress(),
|
address = client.transp.remoteAddress(),
|
||||||
msg_len = len(value)
|
msg_len = len(value)
|
||||||
|
trace "Message", msg = value
|
||||||
client.processMessage(value)
|
client.processMessage(value)
|
||||||
|
|
||||||
# async loop reconnection and waiting
|
# async loop reconnection and waiting
|
||||||
|
|||||||
@ -72,7 +72,8 @@ proc validateRequest(transp: StreamTransport,
|
|||||||
return
|
return
|
||||||
|
|
||||||
var ctype = header["Content-Type"]
|
var ctype = header["Content-Type"]
|
||||||
if ctype.toLowerAscii() != "application/json":
|
# might be "application/json; charset=utf-8"
|
||||||
|
if "application/json" notin ctype.toLowerAscii():
|
||||||
# Content-Type header is not "application/json"
|
# Content-Type header is not "application/json"
|
||||||
debug "Content type must be application/json",
|
debug "Content type must be application/json",
|
||||||
address = transp.remoteAddress()
|
address = transp.remoteAddress()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user