diff --git a/ixwebsocket/IXHttpClient.cpp b/ixwebsocket/IXHttpClient.cpp index 48700f50..871be336 100644 --- a/ixwebsocket/IXHttpClient.cpp +++ b/ixwebsocket/IXHttpClient.cpp @@ -209,6 +209,12 @@ namespace ix ss << "User-Agent: " << userAgent() << "\r\n"; } + // Set an origin header if missing + if (args->extraHeaders.find("Origin") == args->extraHeaders.end()) + { + ss << "Origin: " << protocol << "://" << host << ":" << port << "\r\n"; + } + if (verb == kPost || verb == kPut || verb == kPatch || _forceBody) { // Set request compression header diff --git a/ixwebsocket/IXWebSocketHandshake.cpp b/ixwebsocket/IXWebSocketHandshake.cpp index a0216dd7..206b0790 100644 --- a/ixwebsocket/IXWebSocketHandshake.cpp +++ b/ixwebsocket/IXWebSocketHandshake.cpp @@ -87,6 +87,7 @@ namespace ix WebSocketInitResult WebSocketHandshake::clientHandshake( const std::string& url, const WebSocketHttpHeaders& extraHeaders, + const std::string& protocol, const std::string& host, const std::string& path, int port, @@ -125,6 +126,12 @@ namespace ix ss << "User-Agent: " << userAgent() << "\r\n"; } + // Set an origin header if missing + if (extraHeaders.find("Origin") == extraHeaders.end()) + { + ss << "Origin: " << protocol << "://" << host << ":" << port << "\r\n"; + } + for (auto& it : extraHeaders) { ss << it.first << ": " << it.second << "\r\n"; diff --git a/ixwebsocket/IXWebSocketHandshake.h b/ixwebsocket/IXWebSocketHandshake.h index 3c153791..a6bf2a15 100644 --- a/ixwebsocket/IXWebSocketHandshake.h +++ b/ixwebsocket/IXWebSocketHandshake.h @@ -31,6 +31,7 @@ namespace ix WebSocketInitResult clientHandshake(const std::string& url, const WebSocketHttpHeaders& extraHeaders, + const std::string& protocol, const std::string& host, const std::string& path, int port, diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp index 75519fba..ec25465e 100644 --- a/ixwebsocket/IXWebSocketTransport.cpp +++ b/ixwebsocket/IXWebSocketTransport.cpp @@ -140,7 +140,7 @@ namespace ix _enablePerMessageDeflate); result = webSocketHandshake.clientHandshake( - remoteUrl, headers, host, path, port, timeoutSecs); + remoteUrl, headers, protocol, host, path, port, timeoutSecs); if (result.http_status >= 300 && result.http_status < 400) {