Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions ixwebsocket/IXWebSocketHttpHeaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "IXSocket.h"
#include <algorithm>
#include <locale>

namespace ix
{
Expand Down Expand Up @@ -47,23 +46,25 @@ namespace ix
{
line[i] = '\0';
std::string lineStr(line);
// 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;
// subtract 1 for '\0', 1 for '\n', 1 for '\r',
// 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] == ' ')
while (start < (int) lineStr.size() && lineStr[start] == ' ')
{
start++;
}

std::string name(lineStr.substr(0, colon));
std::string value(lineStr.substr(start, lineStr.size() - start - 2));
std::string value;
if (start < (int) lineStr.size())
{
value = lineStr.substr(start);
// trim trailing whitespace (\r, \n, spaces)
value.erase(std::find_if(value.rbegin(),
value.rend(),
[](unsigned char c) { return !std::isspace(c); })
.base(),
value.end());
}

headers[name] = value;
}
Expand Down
Loading