diff --git a/src/WebSockets.h b/src/WebSockets.h index 592dda8..1265ca1 100644 --- a/src/WebSockets.h +++ b/src/WebSockets.h @@ -270,6 +270,7 @@ typedef struct { String plainAuthorization; ///< Base64 encoded Auth request String extraHeaders; + String userAgentHeader; bool cHttpHeadersValid; ///< non-websocket http header validity indicator size_t cMandatoryHeadersCount; ///< non-websocket mandatory http headers present count diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index db15e5b..aaaec28 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -99,6 +99,7 @@ void WebSocketsClient::beginSSL(const char * host, uint16_t port, const char * u _client.isSSL = true; _fingerprint = fingerprint; _CA_cert = NULL; + _isSecure = true; } void WebSocketsClient::beginSSL(String host, uint16_t port, String url, String fingerprint, String protocol) { @@ -110,7 +111,16 @@ void WebSocketsClient::beginSslWithCA(const char * host, uint16_t port, const ch _client.isSSL = true; _fingerprint = ""; _CA_cert = CA_cert; + _isSecure = true; } + +/** + * disables certificate checks for SSL connections. + */ +void WebSocketsClient::setInsecure() { + _isSecure = false; +} + #endif void WebSocketsClient::beginSocketIO(const char * host, uint16_t port, const char * url, const char * protocol) { @@ -128,6 +138,7 @@ void WebSocketsClient::beginSocketIOSSL(const char * host, uint16_t port, const _client.isSocketIO = true; _client.isSSL = true; _fingerprint = ""; + _isSecure = true; } void WebSocketsClient::beginSocketIOSSL(String host, uint16_t port, String url, String protocol) { @@ -140,6 +151,7 @@ void WebSocketsClient::beginSocketIOSSLWithCA(const char * host, uint16_t port, _client.isSSL = true; _fingerprint = ""; _CA_cert = CA_cert; + _isSecure = true; } #endif @@ -164,6 +176,11 @@ void WebSocketsClient::loop(void) { } _client.ssl = new WEBSOCKETS_NETWORK_SSL_CLASS(); _client.tcp = _client.ssl; + + if (!_isSecure) { + _client.ssl->setInsecure(); + } + if(_CA_cert) { DEBUG_WEBSOCKETS("[WS-Client] setting CA certificate"); #if defined(ESP32) @@ -343,6 +360,14 @@ void WebSocketsClient::setExtraHeaders(const char * extraHeaders) { _client.extraHeaders = extraHeaders; } +/** + * set an user agent which will override the default user agent. + * @param userAgent the user agent header to set + */ +void WebSocketsClient::setUserAgent(const char * userAgent) { + _client.userAgentHeader = userAgent; +} + /** * set the reconnect Interval * how long to wait after a connection initiate failed @@ -571,7 +596,12 @@ void WebSocketsClient::sendHeader(WSclient_t * client) { handshake += client->extraHeaders + NEW_LINE; } - handshake += WEBSOCKETS_STRING("User-Agent: arduino-WebSocket-Client\r\n"); + if (client->userAgentHeader.length() > 0) { + handshake += WEBSOCKETS_STRING("User-Agent: ") + client->userAgentHeader; + } else { + handshake += WEBSOCKETS_STRING("User-Agent: arduino-WebSocket-Client\r\n"); + } + if(client->base64Authorization.length() > 0) { handshake += WEBSOCKETS_STRING("Authorization: Basic "); diff --git a/src/WebSocketsClient.h b/src/WebSocketsClient.h index ed3f630..787474c 100644 --- a/src/WebSocketsClient.h +++ b/src/WebSocketsClient.h @@ -55,6 +55,7 @@ class WebSocketsClient : protected WebSockets { void beginSocketIOSSL(const char * host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * protocol = "arduino"); void beginSocketIOSSL(String host, uint16_t port, String url = "/socket.io/?EIO=3", String protocol = "arduino"); void beginSocketIOSSLWithCA(const char * host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * CA_cert = NULL, const char * protocol = "arduino"); + void setInsecure(); #endif #if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC) @@ -85,9 +86,10 @@ class WebSocketsClient : protected WebSockets { void setAuthorization(const char * auth); void setExtraHeaders(const char * extraHeaders = NULL); - + void setUserAgent(const char * userAgent); + void setReconnectInterval(unsigned long time); - + void enableHeartbeat(uint32_t pingInterval, uint32_t pongTimeout, uint8_t disconnectTimeoutCount); void disableHeartbeat(); @@ -100,6 +102,7 @@ class WebSocketsClient : protected WebSockets { #if defined(HAS_SSL) String _fingerprint; const char * _CA_cert; + bool _isSecure; #endif WSclient_t _client;