forked from cory/tildefriends
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
This commit is contained in:
parent
72e5fe5b8f
commit
c1890775dc
13
src/http.c
13
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user