Compare commits

...

1 Commits

Author SHA1 Message Date
Benjamin Sergeant
4027f9282b Set an origin header in websocket and http clients 2023-04-01 09:14:59 -07:00
4 changed files with 15 additions and 1 deletions

View File

@ -209,6 +209,12 @@ namespace ix
ss << "User-Agent: " << userAgent() << "\r\n"; 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) if (verb == kPost || verb == kPut || verb == kPatch || _forceBody)
{ {
// Set request compression header // Set request compression header

View File

@ -87,6 +87,7 @@ namespace ix
WebSocketInitResult WebSocketHandshake::clientHandshake( WebSocketInitResult WebSocketHandshake::clientHandshake(
const std::string& url, const std::string& url,
const WebSocketHttpHeaders& extraHeaders, const WebSocketHttpHeaders& extraHeaders,
const std::string& protocol,
const std::string& host, const std::string& host,
const std::string& path, const std::string& path,
int port, int port,
@ -125,6 +126,12 @@ namespace ix
ss << "User-Agent: " << userAgent() << "\r\n"; 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) for (auto& it : extraHeaders)
{ {
ss << it.first << ": " << it.second << "\r\n"; ss << it.first << ": " << it.second << "\r\n";

View File

@ -31,6 +31,7 @@ namespace ix
WebSocketInitResult clientHandshake(const std::string& url, WebSocketInitResult clientHandshake(const std::string& url,
const WebSocketHttpHeaders& extraHeaders, const WebSocketHttpHeaders& extraHeaders,
const std::string& protocol,
const std::string& host, const std::string& host,
const std::string& path, const std::string& path,
int port, int port,

View File

@ -140,7 +140,7 @@ namespace ix
_enablePerMessageDeflate); _enablePerMessageDeflate);
result = webSocketHandshake.clientHandshake( 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) if (result.http_status >= 300 && result.http_status < 400)
{ {