File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -226,6 +226,8 @@ typedef struct {
226226 String base64Authorization; // /< Base64 encoded Auth request
227227 String plainAuthorization; // /< Base64 encoded Auth request
228228
229+ String extraHeaders;
230+
229231 bool cHttpHeadersValid; // /< non-websocket http header validity indicator
230232 size_t cMandatoryHeadersCount; // /< non-websocket mandatory http headers present count
231233
Original file line number Diff line number Diff line change 2929WebSocketsClient::WebSocketsClient () {
3030 _cbEvent = NULL ;
3131 _client.num = 0 ;
32+ _client.extraHeaders = " Origin: file://" ;
3233}
3334
3435WebSocketsClient::~WebSocketsClient () {
@@ -274,6 +275,15 @@ void WebSocketsClient::setAuthorization(const char * auth) {
274275 }
275276}
276277
278+ /* *
279+ * set extra headers for the http request;
280+ * separate headers by "\r\n"
281+ * @param extraHeaders const char * extraHeaders
282+ */
283+ void WebSocketsClient::setExtraHeaders (const char * extraHeaders) {
284+ _client.extraHeaders = extraHeaders;
285+ }
286+
277287// #################################################################################
278288// #################################################################################
279289// #################################################################################
@@ -479,10 +489,8 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
479489handshake += WEBSOCKETS_STRING (" Connection: keep-alive\r\n " );
480490}
481491
482- #ifndef WEBSOCKET_HEADERS_NO_ORIGIN
483- // add origin header if requested
484- handshake += WEBSOCKETS_STRING (" Origin: file://\r\n " );
485- #endif
492+ // add extra headers; by default this includes "Origin: file://"
493+ handshake += client->extraHeaders + NEW_LINE;
486494
487495handshake += WEBSOCKETS_STRING (" User-Agent: arduino-WebSocket-Client\r\n " );
488496
Original file line number Diff line number Diff line change @@ -80,6 +80,9 @@ class WebSocketsClient: private WebSockets {
8080
8181 void setAuthorization (const char * user, const char * password);
8282 void setAuthorization (const char * auth);
83+
84+ void setExtraHeaders (char * extraHeaders);
85+ void setExtraHeaders (const char * extraHeaders);
8386
8487 protected:
8588 String _host;
You can’t perform that action at this time.
0 commit comments