From 78f2af5bac5634770fd71adcbd295628524b6cfa Mon Sep 17 00:00:00 2001 From: Tanguy Cizain Date: Fri, 25 Jun 2021 11:22:10 +0200 Subject: [PATCH] import json_ser and use ord --- ws/http/server.nim | 8 ++++++-- ws/session.nim | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ws/http/server.nim b/ws/http/server.nim index b6d7a55f..622f8a60 100644 --- a/ws/http/server.nim +++ b/ws/http/server.nim @@ -15,6 +15,10 @@ import pkg/[ chronicles, httputils] +#required to log addresses in chronicle's json mode +import json_serialization/std/net + + import ./common type @@ -38,13 +42,13 @@ proc validateRequest( ## if header.meth notin {MethodGet}: - trace "GET method is only allowed", address = $stream.tsource.remoteAddress() + trace "GET method is only allowed", address = stream.tsource.remoteAddress() await stream.sendError(Http405, version = header.version) return ReqStatus.Error var hlen = header.contentLength() if hlen < 0 or hlen > MaxHttpRequestSize: - trace "Invalid header length", address = $stream.tsource.remoteAddress() + trace "Invalid header length", address = stream.tsource.remoteAddress() await stream.sendError(Http413, version = header.version) return ReqStatus.Error diff --git a/ws/session.nim b/ws/session.nim index 0978ad7d..72caa9fc 100644 --- a/ws/session.nim +++ b/ws/session.nim @@ -184,7 +184,7 @@ proc handleClose*( raise newException(WSInvalidUTF8, "Invalid UTF8 sequence detected in close reason") - trace "Handling close message", code = $code, reason + trace "Handling close message", code = ord(code), reason if not isNil(ws.onClose): try: (code, reason) = ws.onClose(code, reason) @@ -197,7 +197,7 @@ proc handleClose*( # don't respond to a terminated connection if ws.readyState != ReadyState.Closing: ws.readyState = ReadyState.Closing - trace "Sending close", code = $code, reason + trace "Sending close", code = ord(code), reason await ws.send(prepareCloseBody(code, reason), Opcode.Close) ws.readyState = ReadyState.Closed