Fix webscoket close and fix test cases.

This commit is contained in:
Arijit Das 2021-04-14 16:37:38 +05:30 committed by jangko
parent 51d834a0a1
commit f8cfcd1f99
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 4 additions and 6 deletions

View File

@ -36,7 +36,7 @@ suite "Test websocket TLS handshake":
test "Test for websocket TLS incorrect protocol":
proc cb(r: RequestFence): Future[HttpResponseRef] {.async.} =
if r.isErr():
return
return dumbResponse()
let request = r.get()
check request.uri.path == "/wss"
@ -64,7 +64,7 @@ suite "Test websocket TLS handshake":
test "Test for websocket TLS incorrect version":
proc cb(r: RequestFence): Future[HttpResponseRef] {.async.} =
if r.isErr():
return
return dumbResponse()
let request = r.get()
check request.uri.path == "/wss"
@ -104,7 +104,6 @@ suite "Test websocket TLS handshake":
check request.headers.getString("Sec-WebSocket-Version") == $WSDefaultVersion
check request.headers.contains("Sec-WebSocket-Key")
discard await request.respond(Http200, "Connection established")
let res = SecureHttpServerRef.new(

View File

@ -53,8 +53,7 @@ suite "Test handshake":
test "Test for incorrect version":
proc cb(r: RequestFence): Future[HttpResponseRef] {.async.} =
if r.isErr():
return
return dumbResponse()
let request = r.get()
check request.uri.path == "/ws"
expect WSVersionError:
@ -88,7 +87,6 @@ suite "Test handshake":
check request.headers.getString("Sec-WebSocket-Version") == $WSDefaultVersion
check request.headers.contains("Sec-WebSocket-Key")
discard await request.respond(Http200, "Connection established")
let res = HttpServerRef.new(address, cb)

View File

@ -392,6 +392,7 @@ proc handleClose*(ws: WebSocket, frame: Frame, payLoad: seq[byte] = @[]) {.async
if payLoad.len == 1:
raise newException(WSPayloadLengthError, "Invalid close frame with payload length 1!")
elif payLoad.len > 1:
# first two bytes are the status
let ccode = uint16.fromBytesBE(payLoad[0..<2])