add new message type when receiving message fragments

This commit is contained in:
Benjamin Sergeant 2019-03-11 11:12:43 -07:00
parent 03abe77b5f
commit 892ea375e3
7 changed files with 23 additions and 4 deletions

View File

@ -252,6 +252,11 @@ namespace ix
{ {
webSocketMessageType = WebSocket_MessageType_Pong; webSocketMessageType = WebSocket_MessageType_Pong;
} break; } break;
case WebSocketTransport::FRAGMENT:
{
webSocketMessageType = WebSocket_MessageType_Fragment;
} break;
} }
WebSocketErrorInfo webSocketErrorInfo; WebSocketErrorInfo webSocketErrorInfo;

View File

@ -39,7 +39,8 @@ namespace ix
WebSocket_MessageType_Close = 2, WebSocket_MessageType_Close = 2,
WebSocket_MessageType_Error = 3, WebSocket_MessageType_Error = 3,
WebSocket_MessageType_Ping = 4, WebSocket_MessageType_Ping = 4,
WebSocket_MessageType_Pong = 5 WebSocket_MessageType_Pong = 5,
WebSocket_MessageType_Fragment = 6
}; };
struct WebSocketOpenInfo struct WebSocketOpenInfo

View File

@ -392,6 +392,10 @@ namespace ix
emitMessage(MSG, getMergedChunks(), ws, onMessageCallback); emitMessage(MSG, getMergedChunks(), ws, onMessageCallback);
_chunks.clear(); _chunks.clear();
} }
else
{
emitMessage(FRAGMENT, std::string(), ws, onMessageCallback);
}
} }
} }
else if (ws.opcode == wsheader_type::PING) else if (ws.opcode == wsheader_type::PING)
@ -475,7 +479,7 @@ namespace ix
size_t wireSize = message.size(); size_t wireSize = message.size();
// When the RSV1 bit is 1 it means the message is compressed // When the RSV1 bit is 1 it means the message is compressed
if (_enablePerMessageDeflate && ws.rsv1) if (_enablePerMessageDeflate && ws.rsv1 && messageKind != FRAGMENT)
{ {
std::string decompressedMessage; std::string decompressedMessage;
bool success = _perMessageDeflate.decompress(message, decompressedMessage); bool success = _perMessageDeflate.decompress(message, decompressedMessage);

View File

@ -45,7 +45,8 @@ namespace ix
{ {
MSG, MSG,
PING, PING,
PONG PONG,
FRAGMENT
}; };
using OnMessageCallback = std::function<void(const std::string&, using OnMessageCallback = std::function<void(const std::string&,

View File

@ -31,7 +31,7 @@ int main(int argc, char** argv)
std::string data; std::string data;
std::string headers; std::string headers;
std::string output; std::string output;
std::string hostname; std::string hostname("127.0.0.1");
bool headersOnly = false; bool headersOnly = false;
bool followRedirects = false; bool followRedirects = false;
bool verbose = false; bool verbose = false;

View File

@ -52,6 +52,10 @@ namespace ix
ss << "HTTP Status: " << error.http_status << std::endl; ss << "HTTP Status: " << error.http_status << std::endl;
std::cerr << ss.str(); std::cerr << ss.str();
} }
else if (messageType == ix::WebSocket_MessageType_Fragment)
{
std::cerr << "Received message fragment" << std::endl;
}
else if (messageType == ix::WebSocket_MessageType_Message) else if (messageType == ix::WebSocket_MessageType_Message)
{ {
std::cerr << "Received " << wireSize << " bytes" << std::endl; std::cerr << "Received " << wireSize << " bytes" << std::endl;

View File

@ -52,6 +52,10 @@ namespace ix
ss << "HTTP Status: " << error.http_status << std::endl; ss << "HTTP Status: " << error.http_status << std::endl;
std::cerr << ss.str(); std::cerr << ss.str();
} }
else if (messageType == ix::WebSocket_MessageType_Fragment)
{
std::cerr << "Received message fragment" << std::endl;
}
else if (messageType == ix::WebSocket_MessageType_Message) else if (messageType == ix::WebSocket_MessageType_Message)
{ {
std::cerr << "Received " << wireSize << " bytes" << std::endl; std::cerr << "Received " << wireSize << " bytes" << std::endl;