Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
fix secKey encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Menduist authored and zah committed Jul 28, 2021
1 parent 002b21b commit 3b9d5c6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/news.nim
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,16 @@ proc newWebSocket*(url: string, headers: StringTableRef = nil,
urlPath.add("?" & uri.query)
if urlPath.len == 0:
urlPath = "/"
let secKey = encode($genOid())[16..^1]
let
secKey = ($genOid())[^16..^1]
secKeyEncoded = encode(secKey)
let requestLine = &"GET {urlPath} HTTP/1.1"
let predefinedHeaders = [
&"Host: {uri.hostname}:{$port}",
"Connection: Upgrade",
"Upgrade: websocket",
"Sec-WebSocket-Version: 13",
&"Sec-WebSocket-Key: {secKey}"
&"Sec-WebSocket-Key: {secKeyEncoded}"
]

var customHeaders = ""
Expand All @@ -286,7 +288,7 @@ proc newWebSocket*(url: string, headers: StringTableRef = nil,
while not output.endsWith(static(CRLF & CRLF)):
output.add await ws.transp.recv(1)

let error = validateServerResponse(output, secKey)
let error = validateServerResponse(output, secKeyEncoded)
if error.len > 0:
raise newException(WebSocketError, "WebSocket connection error: " & error)

Expand Down

0 comments on commit 3b9d5c6

Please sign in to comment.