Fix webscoket close and fix test cases.
This commit is contained in:
parent
51d834a0a1
commit
f8cfcd1f99
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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])
|
||||
|
|
Loading…
Reference in New Issue