Skip to content

Commit

Permalink
Allow lowercase WebSocket headers
Browse files Browse the repository at this point in the history
  • Loading branch information
davidepianca98 committed Jun 5, 2022
1 parent 2270892 commit 747e21b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/commonMain/kotlin/socket/tcp/WebSocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class WebSocket(private val socket: Socket) : SocketInterface {
val get = Regex("^GET")

if (get.find(string) != null) {
val match1 = Regex("Sec-WebSocket-Protocol: (.*)")
val match1 = Regex("Sec-WebSocket-Protocol: (.*)", RegexOption.IGNORE_CASE)
if (match1.find(string)?.groups?.get(1)?.value?.contains("mqtt") != true) {
val response = "HTTP/1.1 400 Bad Request\r\n\r\n".encodeToByteArray().toUByteArray()
socket.send(response)
socket.close()
throw IOException("mqtt not included in the subprotocols")
}
val match = Regex("Sec-WebSocket-Key: (.*)")
val match = Regex("Sec-WebSocket-Key: (.*)", RegexOption.IGNORE_CASE)
val key = match.find(string)?.groups?.get(1)?.value
val digest = (key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").encodeToByteArray().sha1().toBase64()
val response = (
Expand Down

0 comments on commit 747e21b

Please sign in to comment.