8000 Switch to setting extra headers via function · faraday-motion/arduinoWebSockets@42ab316 · GitHub
[go: up one dir, main page]

Skip to content

Commit 42ab316

Browse files
committed
Switch to setting extra headers via function
1 parent 86d2e24 commit 42ab316

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/WebSockets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

src/WebSocketsClient.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
WebSocketsClient::WebSocketsClient() {
3030
_cbEvent = NULL;
3131
_client.num = 0;
32+
_client.extraHeaders = "Origin: file://";
3233
}
3334

3435
WebSocketsClient::~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) {
479489
handshake += 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

487495
handshake += WEBSOCKETS_STRING("User-Agent: arduino-WebSocket-Client\r\n");
488496

src/WebSocketsClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)
0