Skip to content

Commit dfa10df

Browse files
authored
Set an origin header in websocket and http clients (#455)
1 parent eb9a7be commit dfa10df

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

ixwebsocket/IXHttpClient.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ namespace ix
209209
ss << "User-Agent: " << userAgent() << "\r\n";
210210
}
211211

212+
// Set an origin header if missing
213+
if (args->extraHeaders.find("Origin") == args->extraHeaders.end())
214+
{
215+
ss << "Origin: " << protocol << "://" << host << ":" << port << "\r\n";
216+
}
217+
212218
if (verb == kPost || verb == kPut || verb == kPatch || _forceBody)
213219
{
214220
// Set request compression header

ixwebsocket/IXWebSocketHandshake.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ namespace ix
8787
WebSocketInitResult WebSocketHandshake::clientHandshake(
8888
const std::string& url,
8989
const WebSocketHttpHeaders& extraHeaders,
90+
const std::string& protocol,
9091
const std::string& host,
9192
const std::string& path,
9293
int port,
@@ -125,6 +126,12 @@ namespace ix
125126
ss << "User-Agent: " << userAgent() << "\r\n";
126127
}
127128

129+
// Set an origin header if missing
130+
if (extraHeaders.find("Origin") == extraHeaders.end())
131+
{
132+
ss << "Origin: " << protocol << "://" << host << ":" << port << "\r\n";
133+
}
134+
128135
for (auto& it : extraHeaders)
129136
{
130137
ss << it.first << ": " << it.second << "\r\n";

ixwebsocket/IXWebSocketHandshake.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace ix
3131

3232
WebSocketInitResult clientHandshake(const std::string& url,
3333
const WebSocketHttpHeaders& extraHeaders,
34+
const std::string& protocol,
3435
const std::string& host,
3536
const std::string& path,
3637
int port,

ixwebsocket/IXWebSocketTransport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace ix
140140
_enablePerMessageDeflate);
141141

142142
result = webSocketHandshake.clientHandshake(
143-
remoteUrl, headers, host, path, port, timeoutSecs);
143+
remoteUrl, headers, protocol, host, path, port, timeoutSecs);
144144

145145
if (result.http_status >= 300 && result.http_status < 400)
146146
{

0 commit comments

Comments
 (0)