mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-07-14 15:56:30 +02:00
Switch to setting extra headers via function
This commit is contained in:
@ -226,6 +226,8 @@ typedef struct {
|
|||||||
String base64Authorization; ///< Base64 encoded Auth request
|
String base64Authorization; ///< Base64 encoded Auth request
|
||||||
String plainAuthorization; ///< Base64 encoded Auth request
|
String plainAuthorization; ///< Base64 encoded Auth request
|
||||||
|
|
||||||
|
String extraHeaders;
|
||||||
|
|
||||||
bool cHttpHeadersValid; ///< non-websocket http header validity indicator
|
bool cHttpHeadersValid; ///< non-websocket http header validity indicator
|
||||||
size_t cMandatoryHeadersCount; ///< non-websocket mandatory http headers present count
|
size_t cMandatoryHeadersCount; ///< non-websocket mandatory http headers present count
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
WebSocketsClient::WebSocketsClient() {
|
WebSocketsClient::WebSocketsClient() {
|
||||||
_cbEvent = NULL;
|
_cbEvent = NULL;
|
||||||
_client.num = 0;
|
_client.num = 0;
|
||||||
|
_client.extraHeaders = "Origin: file://";
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketsClient::~WebSocketsClient() {
|
WebSocketsClient::~WebSocketsClient() {
|
||||||
@ -274,6 +275,15 @@ void WebSocketsClient::setAuthorization(const char * auth) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set extra headers for the http request;
|
||||||
|
* separate headers by "\r\n"
|
||||||
|
* @param extraHeaders const char * extraHeaders
|
||||||
|
*/
|
||||||
|
void WebSocketsClient::setExtraHeaders(const char * extraHeaders) {
|
||||||
|
_client.extraHeaders = extraHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
//#################################################################################
|
//#################################################################################
|
||||||
//#################################################################################
|
//#################################################################################
|
||||||
//#################################################################################
|
//#################################################################################
|
||||||
@ -479,10 +489,8 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
|
|||||||
handshake += WEBSOCKETS_STRING("Connection: keep-alive\r\n");
|
handshake += WEBSOCKETS_STRING("Connection: keep-alive\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WEBSOCKET_HEADERS_NO_ORIGIN
|
// add extra headers; by default this includes "Origin: file://"
|
||||||
// add origin header if requested
|
handshake += client->extraHeaders + NEW_LINE;
|
||||||
handshake += WEBSOCKETS_STRING("Origin: file://\r\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
handshake += WEBSOCKETS_STRING("User-Agent: arduino-WebSocket-Client\r\n");
|
handshake += WEBSOCKETS_STRING("User-Agent: arduino-WebSocket-Client\r\n");
|
||||||
|
|
||||||
|
@ -80,6 +80,9 @@ class WebSocketsClient: private WebSockets {
|
|||||||
|
|
||||||
void setAuthorization(const char * user, const char * password);
|
void setAuthorization(const char * user, const char * password);
|
||||||
void setAuthorization(const char * auth);
|
void setAuthorization(const char * auth);
|
||||||
|
|
||||||
|
void setExtraHeaders(char * extraHeaders);
|
||||||
|
void setExtraHeaders(const char * extraHeaders);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
String _host;
|
String _host;
|
||||||
|
Reference in New Issue
Block a user