import json_ser and use ord

This commit is contained in:
Tanguy Cizain 2021-06-25 11:22:10 +02:00
parent 7e668c4c85
commit 78f2af5bac
No known key found for this signature in database
GPG Key ID: B88D312FB0C84FA5
2 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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