From d36f7bb100bfc2d34d3ac5be6268744eecc1384e Mon Sep 17 00:00:00 2001 From: Thorsten Freitag Date: Mon, 9 May 2016 00:11:42 +1000 Subject: [PATCH] Changed Header value to lower case upgrade, seems to fix connection issues with SAP HCP IoT services. Changed setAuthorization(const char * auth) to send Auth header as is, without BASIC to enable oAuth tokens in header --- src/WebSockets.h | 1 + src/WebSocketsClient.cpp | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/WebSockets.h b/src/WebSockets.h index dbca2b3..fcd85a6 100644 --- a/src/WebSockets.h +++ b/src/WebSockets.h @@ -181,6 +181,7 @@ typedef struct { WSMessageHeader_t cWsHeaderDecode; String base64Authorization; ///< Base64 encoded Auth request + String plainAuthorization; ///< Base64 encoded Auth request #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) String cHttpLine; ///< HTTP header lines diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 6995272..f8821e5 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -62,6 +62,7 @@ void WebSocketsClient::begin(const char *host, uint16_t port, const char * url, _client.cExtensions = ""; _client.cVersion = 0; _client.base64Authorization = ""; + _client.plainAuthorization = ""; #ifdef ESP8266 randomSeed(RANDOM_REG32); @@ -228,7 +229,8 @@ void WebSocketsClient::setAuthorization(const char * user, const char * password */ void WebSocketsClient::setAuthorization(const char * auth) { if(auth) { - _client.base64Authorization = auth; + //_client.base64Authorization = auth; + _client.plainAuthorization = auth; } } @@ -400,7 +402,7 @@ void WebSocketsClient::sendHeader(WSclient_t * client) { "Sec-WebSocket-Key: " + client->cKey + "\r\n"; if(client->cProtocol.length() > 0) { - handshake += "Sec-WebSocket-Protocol: " + client->cProtocol + "\r\n"; + handshake += "Sec-WebSocket-Protocol: " + client->cProtocol + "\r\n"; } if(client->cExtensions.length() > 0) { @@ -411,6 +413,10 @@ void WebSocketsClient::sendHeader(WSclient_t * client) { handshake += "Authorization: Basic " + client->base64Authorization + "\r\n"; } + if(client->plainAuthorization.length() > 0) { + handshake += "Authorization: " + client->plainAuthorization + "\r\n"; + } + handshake += "\r\n"; client->tcp->write(handshake.c_str(), handshake.length()); @@ -442,7 +448,7 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) { String headerValue = headerLine->substring(headerLine->indexOf(':') + 2); if(headerName.equalsIgnoreCase("Connection")) { - if(headerValue.indexOf("Upgrade") >= 0) { + if(headerValue.indexOf("upgrade") >= 0) { client->cIsUpgrade = true; } } else if(headerName.equalsIgnoreCase("Upgrade")) {