core: More slight C/websocket progress.

This commit is contained in:
2025-12-06 12:01:26 -05:00
parent 80c0394ec0
commit 95483b3e55
3 changed files with 100 additions and 12 deletions

View File

@@ -331,7 +331,7 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
{
if (size)
{
connection->body = tf_resize_vec(connection->body, connection->body_length + size);
connection->body = tf_resize_vec(connection->body, connection->body_length + size + 1);
memcpy((char*)connection->body + connection->body_length, data, size);
connection->body_length += size;
}
@@ -385,7 +385,7 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
if (!fin || connection->fragment_length)
{
connection->fragment = tf_resize_vec(connection->fragment, connection->fragment_length + length);
connection->fragment = tf_resize_vec(connection->fragment, connection->fragment_length + length + 1);
memcpy((uint8_t*)connection->fragment + connection->fragment_length, message, length);
connection->fragment_length += length;
}
@@ -394,10 +394,14 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d
{
if (connection->request && connection->request->on_message)
{
uint8_t* payload = connection->fragment_length ? connection->fragment : message;
size_t payload_length = connection->fragment_length ? connection->fragment_length : length;
uint8_t backup = payload[payload_length];
payload[payload_length] = '\0';
tf_trace_begin(connection->http->trace, connection->trace_name ? connection->trace_name : "websocket");
connection->request->on_message(connection->request, connection->fragment_length ? connection->fragment_op_code : op_code,
connection->fragment_length ? connection->fragment : message, connection->fragment_length ? connection->fragment_length : length);
connection->request->on_message(connection->request, connection->fragment_length ? connection->fragment_op_code : op_code, payload, payload_length);
tf_trace_end(connection->http->trace);
payload[payload_length] = backup;
}
connection->fragment_length = 0;
}