http: Move websocket send to http, obvs.
This commit is contained in:
@ -152,44 +152,9 @@ static JSValue _httpd_response_send(JSContext* context, JSValueConst this_val, i
|
||||
tf_http_request_t* request = JS_GetOpaque(this_val, _httpd_request_class_id);
|
||||
int opcode = 0x1;
|
||||
JS_ToInt32(context, &opcode, argv[1]);
|
||||
uint64_t length = 0;
|
||||
size_t length_size = 0;
|
||||
const char* message = JS_ToCStringLen(context, &length_size, argv[0]);
|
||||
length = length_size;
|
||||
uint8_t* copy = tf_malloc(length + 16);
|
||||
bool fin = true;
|
||||
size_t header = 1;
|
||||
copy[0] = (fin ? (1 << 7) : 0) | (opcode & 0xf);
|
||||
if (length < 126)
|
||||
{
|
||||
copy[1] = length;
|
||||
header += 1;
|
||||
}
|
||||
else if (length < (1 << 16))
|
||||
{
|
||||
copy[1] = 126;
|
||||
copy[2] = (length >> 8) & 0xff;
|
||||
copy[3] = (length >> 0) & 0xff;
|
||||
header += 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t high = (length >> 32) & 0xffffffff;
|
||||
uint32_t low = (length >> 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, message, length);
|
||||
tf_http_request_send(request, copy, header + length);
|
||||
tf_free(copy);
|
||||
size_t length = 0;
|
||||
const char* message = JS_ToCStringLen(context, &length, argv[0]);
|
||||
tf_http_request_websocket_send(request, opcode, message, length);
|
||||
JS_FreeCString(context, message);
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
Reference in New Issue
Block a user