mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-06-26 23:41:38 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
6972f7a84e | |||
93b0b9eeaf | |||
dd14850bb6 | |||
d36f7bb100 | |||
10a8d3ca67 | |||
4f55c36c80 |
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -392,15 +394,16 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
|
||||
#endif
|
||||
|
||||
String handshake = "GET " + client->cUrl + " HTTP/1.1\r\n"
|
||||
"Host: " + _host + "\r\n"
|
||||
"Upgrade: websocket\r\n"
|
||||
"Host: " + _host + ":" + _port + "\r\n"
|
||||
"Connection: Upgrade\r\n"
|
||||
"Upgrade: websocket\r\n"
|
||||
"Origin: file://\r\n"
|
||||
"User-Agent: arduino-WebSocket-Client\r\n"
|
||||
"Sec-WebSocket-Version: 13\r\n"
|
||||
"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 +414,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 +449,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.equalsIgnoreCase("upgrade")) {
|
||||
client->cIsUpgrade = true;
|
||||
}
|
||||
} else if(headerName.equalsIgnoreCase("Upgrade")) {
|
||||
@ -620,6 +627,3 @@ void WebSocketsClient::asyncConnect() {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user