From 00be8c7833b32a377e3d1f7135abf40697bc7ee0 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Wed, 16 Mar 2016 11:55:21 +0200 Subject: [PATCH] Make the `Sec-WebSocket-Protocol` header optional Some server implementations (e.g. slack bots api) don't accept the connection if `Sec-WebSocket-Protocol` is specified. --- src/WebSocketsClient.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index fca918c..6995272 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -397,9 +397,12 @@ void WebSocketsClient::sendHeader(WSclient_t * client) { "Connection: Upgrade\r\n" "User-Agent: arduino-WebSocket-Client\r\n" "Sec-WebSocket-Version: 13\r\n" - "Sec-WebSocket-Protocol: " + client->cProtocol +"\r\n" "Sec-WebSocket-Key: " + client->cKey + "\r\n"; + if(client->cProtocol.length() > 0) { + handshake += "Sec-WebSocket-Protocol: " + client->cProtocol + "\r\n"; + } + if(client->cExtensions.length() > 0) { handshake += "Sec-WebSocket-Extensions: " + client->cExtensions + "\r\n"; }