mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-06-27 16:01:01 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
6972f7a84e | |||
93b0b9eeaf | |||
dd14850bb6 | |||
d36f7bb100 | |||
10a8d3ca67 | |||
4f55c36c80 |
@ -181,6 +181,7 @@ typedef struct {
|
|||||||
WSMessageHeader_t cWsHeaderDecode;
|
WSMessageHeader_t cWsHeaderDecode;
|
||||||
|
|
||||||
String base64Authorization; ///< Base64 encoded Auth request
|
String base64Authorization; ///< Base64 encoded Auth request
|
||||||
|
String plainAuthorization; ///< Base64 encoded Auth request
|
||||||
|
|
||||||
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
|
||||||
String cHttpLine; ///< HTTP header lines
|
String cHttpLine; ///< HTTP header lines
|
||||||
|
@ -62,6 +62,7 @@ void WebSocketsClient::begin(const char *host, uint16_t port, const char * url,
|
|||||||
_client.cExtensions = "";
|
_client.cExtensions = "";
|
||||||
_client.cVersion = 0;
|
_client.cVersion = 0;
|
||||||
_client.base64Authorization = "";
|
_client.base64Authorization = "";
|
||||||
|
_client.plainAuthorization = "";
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
randomSeed(RANDOM_REG32);
|
randomSeed(RANDOM_REG32);
|
||||||
@ -228,7 +229,8 @@ void WebSocketsClient::setAuthorization(const char * user, const char * password
|
|||||||
*/
|
*/
|
||||||
void WebSocketsClient::setAuthorization(const char * auth) {
|
void WebSocketsClient::setAuthorization(const char * auth) {
|
||||||
if(auth) {
|
if(auth) {
|
||||||
_client.base64Authorization = auth;
|
//_client.base64Authorization = auth;
|
||||||
|
_client.plainAuthorization = auth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,9 +394,10 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
String handshake = "GET " + client->cUrl + " HTTP/1.1\r\n"
|
String handshake = "GET " + client->cUrl + " HTTP/1.1\r\n"
|
||||||
"Host: " + _host + "\r\n"
|
"Host: " + _host + ":" + _port + "\r\n"
|
||||||
"Upgrade: websocket\r\n"
|
|
||||||
"Connection: Upgrade\r\n"
|
"Connection: Upgrade\r\n"
|
||||||
|
"Upgrade: websocket\r\n"
|
||||||
|
"Origin: file://\r\n"
|
||||||
"User-Agent: arduino-WebSocket-Client\r\n"
|
"User-Agent: arduino-WebSocket-Client\r\n"
|
||||||
"Sec-WebSocket-Version: 13\r\n"
|
"Sec-WebSocket-Version: 13\r\n"
|
||||||
"Sec-WebSocket-Key: " + client->cKey + "\r\n";
|
"Sec-WebSocket-Key: " + client->cKey + "\r\n";
|
||||||
@ -411,6 +414,10 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
|
|||||||
handshake += "Authorization: Basic " + client->base64Authorization + "\r\n";
|
handshake += "Authorization: Basic " + client->base64Authorization + "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(client->plainAuthorization.length() > 0) {
|
||||||
|
handshake += "Authorization: " + client->plainAuthorization + "\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
handshake += "\r\n";
|
handshake += "\r\n";
|
||||||
|
|
||||||
client->tcp->write(handshake.c_str(), handshake.length());
|
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);
|
String headerValue = headerLine->substring(headerLine->indexOf(':') + 2);
|
||||||
|
|
||||||
if(headerName.equalsIgnoreCase("Connection")) {
|
if(headerName.equalsIgnoreCase("Connection")) {
|
||||||
if(headerValue.indexOf("Upgrade") >= 0) {
|
if(headerValue.equalsIgnoreCase("upgrade")) {
|
||||||
client->cIsUpgrade = true;
|
client->cIsUpgrade = true;
|
||||||
}
|
}
|
||||||
} else if(headerName.equalsIgnoreCase("Upgrade")) {
|
} else if(headerName.equalsIgnoreCase("Upgrade")) {
|
||||||
@ -620,6 +627,3 @@ void WebSocketsClient::asyncConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user