Skip to content
Open
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
27 changes: 18 additions & 9 deletions ixwebsocket/IXWebSocketHttpHeaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,43 @@ namespace ix
WebSocketHttpHeaders headers;

char line[1024];
int i;

while (true)
{
int colon = 0;

for (i = 0; i < 2 || (i < 1023 && line[i - 2] != '\r' && line[i - 1] != '\n'); ++i)
std::size_t i{0};
int colon = -1;
for(i=0;i<1023;++i)
{
if (!socket->readByte(line + i, isCancellationRequested))
{
return std::make_pair(false, headers);
}

if (line[i] == ':' && colon == 0)
if (line[i] == ':' && colon == -1)
{
colon = static_cast<int>(i);
}
if(line[i] == '\n')
{
colon = i;
++i;
break;
}
}
if (line[0] == '\r' && line[1] == '\n')
if((i == 2 && line[0] == '\r' && line[1] == '\n') || (i == 1 && line[0] == '\n'))
{
break;
}
// strip all \n \r
std::size_t end = i;
auto rbegin = std::reverse_iterator<char*>(line + end);
auto rend = std::reverse_iterator<char*>(line);
auto it = std::find_if(rbegin,rend,[](const unsigned char c){return c != '\r' && c != '\n'; });
end = static_cast<std::size_t>(it.base() - line);
line[end] = '\0';

// line is a single header entry. split by ':', and add it to our
// header map. ignore lines with no colon.
if (colon > 0)
{
line[i] = '\0';
std::string lineStr(line);

int start = colon + 1;
Expand Down
Loading