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; }