From 804ec9246f294be1eed00c4ccdd4f88bb416b38d Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Fri, 22 Mar 2019 15:33:04 -0700 Subject: [PATCH] (server) fix masking bug --- ixwebsocket/IXWebSocketTransport.cpp | 8 ++++---- test/IXTest.cpp | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp index 4173b673..9f9a7a48 100644 --- a/ixwebsocket/IXWebSocketTransport.cpp +++ b/ixwebsocket/IXWebSocketTransport.cpp @@ -124,9 +124,8 @@ namespace ix // Server WebSocketInitResult WebSocketTransport::connectToSocket(int fd, int timeoutSecs) { - // Server should not mask the data it sends to the client (with _useMask = false) - // However our unmasked code is broken right now for some reason, so disabling this. - _useMask = true; + // Server should not mask the data it sends to the client + _useMask = false; std::string errorMsg; _socket = createSocket(fd, errorMsg); @@ -657,7 +656,8 @@ namespace ix std::vector header; header.assign(2 + (message_size >= 126 ? 2 : 0) + - (message_size >= 65536 ? 6 : 0) + 4, 0); + (message_size >= 65536 ? 6 : 0) + + (_useMask ? 4 : 0), 0); header[0] = type; // The fin bit indicate that this is the last fragment. Fin is French for end. diff --git a/test/IXTest.cpp b/test/IXTest.cpp index f80447a5..5abc9d59 100644 --- a/test/IXTest.cpp +++ b/test/IXTest.cpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace ix { @@ -148,4 +149,21 @@ namespace ix 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; + } }