Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions src/WebSocketClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ bool WebSocketClient::analyzeRequest() {
socket_client->print(CRLF);
socket_client->print(F("Sec-WebSocket-Version: 13\r\n"));

#ifdef DEBUGGING
Serial.println("Printing websocket upgrade headers");
Serial.print(F("GET "));
Serial.print(path);
if (issocketio) {
socket_client->print(F("socket.io/?EIO=3&transport=websocket&sid="));
socket_client->print(sid);
}
Serial.print(F(" HTTP/1.1\r\n"));
Serial.print(F("Upgrade: websocket\r\n"));
Serial.print(F("Connection: Upgrade\r\n"));
Serial.print(F("Sec-WebSocket-Key: "));
Serial.print(key);
Serial.print(CRLF);
Serial.print(F("Sec-WebSocket-Protocol: "));
Serial.print(protocol);
Serial.print(CRLF);
Serial.print(F("Sec-WebSocket-Version: 13\r\n"));
#endif


} else {

#ifdef DEBUGGING
Expand Down Expand Up @@ -123,17 +144,29 @@ bool WebSocketClient::analyzeRequest() {
temp += (char)bite;

if ((char)bite == '\n') {
String tempLC = temp;
tempLC.toLowerCase(); // uses case-insensitive header string for parsing to ensure to catch response from servers using different upper/lowercase variants of headers
#ifdef DEBUGGING
Serial.print("Got Header: " + temp);
#endif
if (!foundupgrade && temp.startsWith("Upgrade: websocket")) {
if (!foundupgrade && tempLC.startsWith("upgrade: websocket")) {
foundupgrade = true;
} else if (temp.startsWith("Sec-WebSocket-Accept: ")) {
} else if (tempLC.startsWith("sec-websocket-accept: ")) {
serverKey = temp.substring(22,temp.length() - 2); // Don't save last CR+LF
} else if (!foundsid && temp.startsWith("Set-Cookie: ")) {
foundsid = true;
String tempsid = temp.substring(temp.indexOf("=") + 1, temp.length() - 2); // Don't save last CR+LF
strcpy(sid, tempsid.c_str());
} else if (!foundsid && tempLC.startsWith("set-cookie: ")) {
foundsid = true;
String tempsid;
if (temp.indexOf(";") == -1){ // looks for ";" in cookie header, which indicates more than one cookie value
tempsid = temp.substring(temp.indexOf("=") + 1, temp.length() - 2); // Don't save last CR+LF
}
else {
tempsid = temp.substring(temp.indexOf("=") + 1, temp.indexOf(";")); // assumes sid is first cookie value, discards all other values
}
strcpy(sid, tempsid.c_str());
#ifdef DEBUGGING
Serial.println("Parsing Set-Cookie...");
Serial.println("tempsid: " + tempsid);
#endif
}
temp = "";
}
Expand Down