8000 Fix empty header issue · ROMSDEV/arduinoWebSockets@669f0b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 669f0b4

Browse files
committed
Fix empty header issue
1 parent 32cb052 commit 669f0b4

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

examples/WebSocketClientSockJsAndStomp/WebSocketClientSockJsAndStomp.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void setup() {
137137

138138
// connect to websocket
139139
webSocket.begin(ws_host, ws_port, socketUrl);
140-
webSocket.setExtraHeaders(""); // remove "Origin: file://" header because it breaks the connection with Spring's default websocket config
140+
webSocket.setExtraHeaders(); // remove "Origin: file://" header because it breaks the connection with Spring's default websocket config
141141
// webSocket.setExtraHeaders("foo: I am so funny\r\nbar: not"); // some headers, in case you feel funny
142142
webSocket.onEvent(webSocketEvent);
143143
}

src/WebSocketsClient.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
WebSocketsClient::WebSocketsClient() {
3030
_cbEvent = NULL;
3131
_client.num = 0;
32-
_client.extraHeaders = "Origin: file://";
32+
_client.extraHeaders = WEBSOCKETS_STRING("Origin: file://");
3333
}
3434

3535
WebSocketsClient::~WebSocketsClient() {
@@ -490,8 +490,10 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
490490
}
491491

492492
// add extra headers; by default this includes "Origin: file://"
493-
handshake += client->extraHeaders + NEW_LINE;
494-
493+
if (client->extraHeaders) {
494+
handshake += client->extraHeaders + NEW_LINE;
495+
}
496+
495497
handshake += WEBSOCKETS_STRING("User-Agent: arduino-WebSocket-Client\r\n");
496498

497499
if(client->base64Authorization.length() > 0) {

src/WebSocketsClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class WebSocketsClient: private WebSockets {
8181
void setAuthorization(const char * user, const char * password);
8282
void setAuthorization(const char * auth);
8383

84+
void setExtraHeaders(const char * extraHeaders = NULL);
8485
void setExtraHeaders(char * extraHeaders);
85-
void setExtraHeaders(const char * extraHeaders);
8686

8787
protected:
8888
String _host;

0 commit comments

Comments
 (0)
0