From c1890775dcd829f6048273b2b90656577876774d Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 30 Dec 2023 21:35:53 +0000 Subject: [PATCH] Fixes for fragmented websocket messages. Android is happy, now. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4712 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/http.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/http.c b/src/http.c index c409baa2..a8d7bf8a 100644 --- a/src/http.c +++ b/src/http.c @@ -55,6 +55,7 @@ typedef struct _tf_http_connection_t int websocket_message_index; void* body; void* fragment; + int fragment_op_code; size_t fragment_length; size_t body_length; size_t content_length; @@ -194,6 +195,7 @@ static void _http_builtin_404_handler(tf_http_request_t* request) static void _http_reset_connection(tf_http_connection_t* connection) { + connection->fragment_op_code = 0; connection->fragment_length = 0; connection->body_length = 0; connection->content_length = 0; @@ -277,6 +279,11 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d _http_websocket_mask_in_place(p + mask_start + 4, mask, length); const uint8_t* message = p + mask_start + 4; + if (!fin && !connection->fragment_op_code) + { + connection->fragment_op_code = op_code; + } + if (!fin || connection->fragment_length) { connection->fragment = tf_realloc(connection->fragment, connection->fragment_length + length); @@ -288,7 +295,11 @@ static void _http_add_body_bytes(tf_http_connection_t* connection, const void* d { if (connection->request->on_message) { - connection->request->on_message(connection->request, 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, + connection->fragment_length ? connection->fragment : message, + connection->fragment_length ? connection->fragment_length : length); } connection->fragment_length = 0; }