http: Move websocket send to http, obvs.
This commit is contained in:
37
src/http.c
37
src/http.c
@ -974,9 +974,42 @@ static void _http_write(tf_http_connection_t* connection, const void* data, size
|
||||
}
|
||||
}
|
||||
|
||||
void tf_http_request_send(tf_http_request_t* request, const void* data, size_t size)
|
||||
void tf_http_request_websocket_send(tf_http_request_t* request, int op_code, const void* data, size_t size)
|
||||
{
|
||||
_http_write(request->connection, data, size);
|
||||
uint8_t* copy = tf_malloc(size + 16);
|
||||
bool fin = true;
|
||||
size_t header = 1;
|
||||
copy[0] = (fin ? (1 << 7) : 0) | (op_code & 0xf);
|
||||
if (size < 126)
|
||||
{
|
||||
copy[1] = size;
|
||||
header += 1;
|
||||
}
|
||||
else if (size < (1 << 16))
|
||||
{
|
||||
copy[1] = 126;
|
||||
copy[2] = (size >> 8) & 0xff;
|
||||
copy[3] = (size >> 0) & 0xff;
|
||||
header += 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t high = (size >> 32) & 0xffffffff;
|
||||
uint32_t low = (size >> 0) & 0xffffffff;
|
||||
copy[1] = 127;
|
||||
copy[2] = (high >> 24) & 0xff;
|
||||
copy[3] = (high >> 16) & 0xff;
|
||||
copy[4] = (high >> 8) & 0xff;
|
||||
copy[5] = (high >> 0) & 0xff;
|
||||
copy[6] = (low >> 24) & 0xff;
|
||||
copy[7] = (low >> 16) & 0xff;
|
||||
copy[8] = (low >> 8) & 0xff;
|
||||
copy[9] = (low >> 0) & 0xff;
|
||||
header += 9;
|
||||
}
|
||||
memcpy(copy + header, data, size);
|
||||
_http_write(request->connection, copy, header + size);
|
||||
tf_free(copy);
|
||||
}
|
||||
|
||||
void tf_http_respond(tf_http_request_t* request, int status, const char** headers, int headers_count, const void* body, size_t content_length)
|
||||
|
Reference in New Issue
Block a user