mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
LibWebSocket: Adds capability for receiving fragmented messages
This commit is contained in:
parent
d277d2e1fb
commit
773a64aa5a
2 changed files with 19 additions and 9 deletions
|
@ -406,13 +406,8 @@ void WebSocket::read_frame()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_final_frame = head_bytes[0] & 0x80;
|
|
||||||
if (!is_final_frame) {
|
|
||||||
// FIXME: Support fragmented frames
|
|
||||||
TODO();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto op_code = (WebSocket::OpCode)(head_bytes[0] & 0x0f);
|
auto op_code = (WebSocket::OpCode)(head_bytes[0] & 0x0f);
|
||||||
|
bool is_final_frame = head_bytes[0] & 0x80;
|
||||||
bool is_masked = head_bytes[1] & 0x80;
|
bool is_masked = head_bytes[1] & 0x80;
|
||||||
|
|
||||||
// Parse the payload length.
|
// Parse the payload length.
|
||||||
|
@ -504,9 +499,22 @@ void WebSocket::read_frame()
|
||||||
// We can safely ignore the pong
|
// We can safely ignore the pong
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (op_code == WebSocket::OpCode::Continuation) {
|
if (!is_final_frame) {
|
||||||
// FIXME: Support fragmented frames
|
if (op_code != WebSocket::OpCode::Continuation) {
|
||||||
TODO();
|
// First fragmented message
|
||||||
|
m_initial_fragment_opcode = op_code;
|
||||||
|
}
|
||||||
|
// First and next fragmented message
|
||||||
|
m_fragmented_data_buffer.append(payload.data(), payload_length);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (is_final_frame && op_code == WebSocket::OpCode::Continuation) {
|
||||||
|
// Last fragmented message
|
||||||
|
m_fragmented_data_buffer.append(payload.data(), payload_length);
|
||||||
|
op_code = m_initial_fragment_opcode;
|
||||||
|
payload.clear();
|
||||||
|
payload.append(m_fragmented_data_buffer.data(), m_fragmented_data_buffer.size());
|
||||||
|
m_fragmented_data_buffer.clear();
|
||||||
}
|
}
|
||||||
if (op_code == WebSocket::OpCode::Text) {
|
if (op_code == WebSocket::OpCode::Text) {
|
||||||
notify_message(Message(payload, true));
|
notify_message(Message(payload, true));
|
||||||
|
|
|
@ -112,6 +112,8 @@ private:
|
||||||
RefPtr<WebSocketImpl> m_impl;
|
RefPtr<WebSocketImpl> m_impl;
|
||||||
|
|
||||||
Vector<u8> m_buffered_data;
|
Vector<u8> m_buffered_data;
|
||||||
|
ByteBuffer m_fragmented_data_buffer;
|
||||||
|
WebSocket::OpCode m_initial_fragment_opcode;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue