diff --git a/examples/WebSocketClientSockJsAndStomp/WebSocketClientSockJsAndStomp.ino b/examples/WebSocketClientSockJsAndStomp/WebSocketClientSockJsAndStomp.ino index c8d990f..96ce679 100644 --- a/examples/WebSocketClientSockJsAndStomp/WebSocketClientSockJsAndStomp.ino +++ b/examples/WebSocketClientSockJsAndStomp/WebSocketClientSockJsAndStomp.ino @@ -137,7 +137,7 @@ void setup() { // connect to websocket webSocket.begin(ws_host, ws_port, socketUrl); - webSocket.setExtraHeaders(""); // remove "Origin: file://" header because it breaks the connection with Spring's default websocket config + webSocket.setExtraHeaders(); // remove "Origin: file://" header because it breaks the connection with Spring's default websocket config // webSocket.setExtraHeaders("foo: I am so funny\r\nbar: not"); // some headers, in case you feel funny webSocket.onEvent(webSocketEvent); } diff --git a/src/WebSocketsClient.cpp b/src/WebSocketsClient.cpp index 787b7a5..3faae99 100644 --- a/src/WebSocketsClient.cpp +++ b/src/WebSocketsClient.cpp @@ -29,7 +29,7 @@ WebSocketsClient::WebSocketsClient() { _cbEvent = NULL; _client.num = 0; - _client.extraHeaders = "Origin: file://"; + _client.extraHeaders = WEBSOCKETS_STRING("Origin: file://"); } WebSocketsClient::~WebSocketsClient() { @@ -490,8 +490,10 @@ void WebSocketsClient::sendHeader(WSclient_t * client) { } // add extra headers; by default this includes "Origin: file://" - handshake += client->extraHeaders + NEW_LINE; - + if (client->extraHeaders) { + handshake += client->extraHeaders + NEW_LINE; + } + handshake += WEBSOCKETS_STRING("User-Agent: arduino-WebSocket-Client\r\n"); if(client->base64Authorization.length() > 0) { diff --git a/src/WebSocketsClient.h b/src/WebSocketsClient.h index df9bbef..b097b68 100644 --- a/src/WebSocketsClient.h +++ b/src/WebSocketsClient.h @@ -81,8 +81,8 @@ class WebSocketsClient: private WebSockets { void setAuthorization(const char * user, const char * password); void setAuthorization(const char * auth); + void setExtraHeaders(const char * extraHeaders = NULL); void setExtraHeaders(char * extraHeaders); - void setExtraHeaders(const char * extraHeaders); protected: String _host;