(server) fix masking bug

This commit is contained in:
Benjamin Sergeant 2019-03-22 15:33:04 -07:00
parent f029321664
commit 804ec9246f
2 changed files with 22 additions and 4 deletions

View File

@ -124,9 +124,8 @@ namespace ix
// Server // Server
WebSocketInitResult WebSocketTransport::connectToSocket(int fd, int timeoutSecs) WebSocketInitResult WebSocketTransport::connectToSocket(int fd, int timeoutSecs)
{ {
// Server should not mask the data it sends to the client (with _useMask = false) // Server should not mask the data it sends to the client
// However our unmasked code is broken right now for some reason, so disabling this. _useMask = false;
_useMask = true;
std::string errorMsg; std::string errorMsg;
_socket = createSocket(fd, errorMsg); _socket = createSocket(fd, errorMsg);
@ -657,7 +656,8 @@ namespace ix
std::vector<uint8_t> header; std::vector<uint8_t> header;
header.assign(2 + header.assign(2 +
(message_size >= 126 ? 2 : 0) + (message_size >= 126 ? 2 : 0) +
(message_size >= 65536 ? 6 : 0) + 4, 0); (message_size >= 65536 ? 6 : 0) +
(_useMask ? 4 : 0), 0);
header[0] = type; header[0] = type;
// The fin bit indicate that this is the last fragment. Fin is French for end. // The fin bit indicate that this is the last fragment. Fin is French for end.

View File

@ -16,6 +16,7 @@
#include <iostream> #include <iostream>
#include <stdlib.h> #include <stdlib.h>
#include <stack> #include <stack>
#include <iomanip>
namespace ix namespace ix
{ {
@ -148,4 +149,21 @@ namespace ix
return -1; return -1;
} }
void hexDump(const std::string& prefix,
const std::string& s)
{
std::ostringstream ss;
bool upper_case = false;
for (std::string::size_type i = 0; i < s.length(); ++i)
{
ss << std::hex
<< std::setfill('0')
<< std::setw(2)
<< (upper_case ? std::uppercase : std::nouppercase) << (int)s[i];
}
std::cout << prefix << ": " << s << " => " << ss.str() << std::endl;
}
} }