(client + server) Fix #155 / http header parser should treat the space(s) after the : delimiter as optional. Fixing this bug made us discover that websocket sub-protocols are not properly serialiazed, but start with a ,
This commit is contained in:
parent
feab4dee0f
commit
242c945400
@ -1,6 +1,10 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All changes to this project will be documented in this file.
|
All changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [8.1.3] - 2020-02-21
|
||||||
|
|
||||||
|
(client + server) Fix #155 / http header parser should treat the space(s) after the : delimiter as optional. Fixing this bug made us discover that websocket sub-protocols are not properly serialiazed, but start with a ,
|
||||||
|
|
||||||
## [8.1.2] - 2020-02-18
|
## [8.1.2] - 2020-02-18
|
||||||
|
|
||||||
(WebSocketServer) add option to disable deflate compression, exposed with the -x option to ws echo_server
|
(WebSocketServer) add option to disable deflate compression, exposed with the -x option to ws echo_server
|
||||||
|
@ -191,9 +191,19 @@ namespace ix
|
|||||||
auto subProtocols = getSubProtocols();
|
auto subProtocols = getSubProtocols();
|
||||||
if (!subProtocols.empty())
|
if (!subProtocols.empty())
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
// Sub Protocol strings are comma separated.
|
||||||
|
// Python code to do that is:
|
||||||
|
// >>> ','.join(['json', 'msgpack'])
|
||||||
|
// 'json,msgpack'
|
||||||
|
//
|
||||||
|
int i = 0;
|
||||||
for (auto subProtocol : subProtocols)
|
for (auto subProtocol : subProtocols)
|
||||||
{
|
{
|
||||||
subProtocolsHeader += ",";
|
if (i++ != 0)
|
||||||
|
{
|
||||||
|
subProtocolsHeader += ",";
|
||||||
|
}
|
||||||
subProtocolsHeader += subProtocol;
|
subProtocolsHeader += subProtocol;
|
||||||
}
|
}
|
||||||
headers["Sec-WebSocket-Protocol"] = subProtocolsHeader;
|
headers["Sec-WebSocket-Protocol"] = subProtocolsHeader;
|
||||||
|
@ -66,12 +66,23 @@ namespace ix
|
|||||||
{
|
{
|
||||||
line[i] = '\0';
|
line[i] = '\0';
|
||||||
std::string lineStr(line);
|
std::string lineStr(line);
|
||||||
// colon is ':', colon+1 is ' ', colon+2 is the start of the value.
|
// colon is ':', usually colon+1 is ' ', and colon+2 is the start of the value.
|
||||||
|
// some webservers do not put a space after the colon character, so
|
||||||
|
// the start of the value might be farther than colon+2.
|
||||||
|
// The spec says that space after the : should be discarded.
|
||||||
// i is end of string (\0), i-colon is length of string minus key;
|
// i is end of string (\0), i-colon is length of string minus key;
|
||||||
// subtract 1 for '\0', 1 for '\n', 1 for '\r',
|
// subtract 1 for '\0', 1 for '\n', 1 for '\r',
|
||||||
// 1 for the ' ' after the ':', and total is -4
|
// 1 for the ' ' after the ':', and total is -4
|
||||||
|
// since we use an std::string later on and don't account for '\0',
|
||||||
|
// plus the optional first space, total is -2
|
||||||
|
int start = colon + 1;
|
||||||
|
while (lineStr[start] == ' ')
|
||||||
|
{
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
|
||||||
std::string name(lineStr.substr(0, colon));
|
std::string name(lineStr.substr(0, colon));
|
||||||
std::string value(lineStr.substr(colon + 2, i - colon - 4));
|
std::string value(lineStr.substr(start, lineStr.size() - start - 2));
|
||||||
|
|
||||||
headers[name] = value;
|
headers[name] = value;
|
||||||
}
|
}
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "8.1.2"
|
#define IX_WEBSOCKET_VERSION "8.1.3"
|
||||||
|
Loading…
Reference in New Issue
Block a user