From 1083b2972a183c4e1221f0ea3671dc7ad193f92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Fri, 25 Jan 2019 20:11:01 +0100 Subject: [PATCH] support Content-Type headers with specified charset and add RPC message content to the debugging output (at the TRACE level, disabled by default) --- json_rpc/clients/httpclient.nim | 9 ++++++--- json_rpc/servers/httpserver.nim | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/json_rpc/clients/httpclient.nim b/json_rpc/clients/httpclient.nim index a7abd70..a991277 100644 --- a/json_rpc/clients/httpclient.nim +++ b/json_rpc/clients/httpclient.nim @@ -52,7 +52,8 @@ proc validateResponse*(transp: StreamTransport, return 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" debug "Content type must be application/json", address = transp.remoteAddress() @@ -186,12 +187,13 @@ proc call*(client: RpcHttpClient, name: string, 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 + address = client.transp.remoteAddress(), msg_len = len(value) client.transp.close() raise newException(ValueError, "Transport error") else: debug "Message sent to RPC server", address = client.transp.remoteAddress(), - msg_len = res + msg_len = len(value) + trace "Message", msg = value # completed by processMessage. var newFut = newFuture[Response]() @@ -211,6 +213,7 @@ proc processData(client: RpcHttpClient) {.async.} = debug "Received response from RPC server", address = client.transp.remoteAddress(), msg_len = len(value) + trace "Message", msg = value client.processMessage(value) # async loop reconnection and waiting diff --git a/json_rpc/servers/httpserver.nim b/json_rpc/servers/httpserver.nim index 4b10bc5..76f015e 100644 --- a/json_rpc/servers/httpserver.nim +++ b/json_rpc/servers/httpserver.nim @@ -72,7 +72,8 @@ proc validateRequest(transp: StreamTransport, return 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" debug "Content type must be application/json", address = transp.remoteAddress()