8000 Merge pull request #77 from thorstenfreitag/master · coderGods/arduinoWebSockets@93b0b9e · GitHub
[go: up one dir, main page]

Skip to content

Commit 93b0b9e

Browse files
committed
Merge pull request Links2004#77 from thorstenfreitag/master
Compatibility for broken servers and additional authentication option instead of just basic
2 parents b3efb31 + dd14850 commit 93b0b9e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/WebSockets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ typedef struct {
181181
WSMessageHeader_t cWsHeaderDecode;
182182

183183
String base64Authorization; ///< Base64 encoded Auth request
184+
String plainAuthorization; ///< Base64 encoded Auth request
184185

185186
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
186187
String cHttpLine; ///< HTTP header lines

src/WebSocketsClient.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void WebSocketsClient::begin(const char *host, uint16_t port, const char * url,
6262
_client.cExtensions = "";
6363
_client.cVersion = 0;
6464
_client.base64Authorization = "";
65+
_client.plainAuthorization = "";
6566

6667
#ifdef ESP8266
6768
randomSeed(RANDOM_REG32);
@@ -228,7 +229,8 @@ void WebSocketsClient::setAuthorization(const char * user, const char * password
228229
*/
229230
void WebSocketsClient::setAuthorization(const char * auth) {
230231
if(auth) {
231-
_client.base64Authorization = auth;
232+
//_client.base64Authorization = auth;
233+
_client.plainAuthorization = auth;
232234
}
233235
}
234236

@@ -400,7 +402,7 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
400402
"Sec-WebSocket-Key: " + client->cKey + "\r\n";
401403

402404
if(client->cProtocol.length() > 0) {
403-
handshake += "Sec-WebSocket-Protocol: " + client->cProtocol + "\r\n";
405+
handshake += "Sec-WebSocket-Protocol: " + client->cProtocol + "\r\n";
404406
}
405407

406408
if(client->cExtensions.length() > 0) {
@@ -411,6 +413,10 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
411413
handshake += "Authorization: Basic " + client->base64Authorization + "\r\n";
412414
}
413415

416+
if(client->plainAuthorization.length() > 0) {
417+
handshake += "Authorization: " + client->plainAuthorization + "\r\n";
418+
}
419+
414420
handshake += "\r\n";
415421

416422
client->tcp->write(handshake.c_str(), handshake.length());
@@ -442,7 +448,7 @@ void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {
442448
String headerValue = headerLine->substring(headerLine->indexOf(':') + 2);
443449

444450
if(headerName.equalsIgnoreCase("Connection")) {
445-
if(headerValue.indexOf("Upgrade") >= 0) {
451+
if(headerValue.equalsIgnoreCase("upgrade")) {
446452
client->cIsUpgrade = true;
447453
}
448454
} else if(headerName.equalsIgnoreCase("Upgrade")) {

0 commit comments

Comments
 (0)
0