core: Get rid of the httpd JS object. Potential progress on #108.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 30m37s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 30m37s
This commit is contained in:
@ -47,7 +47,6 @@ static const char* _make_set_session_cookie_header(tf_http_request_t* request, c
|
||||
const char** _form_data_decode(const char* data, int length);
|
||||
const char* _form_data_get(const char** form_data, const char* key);
|
||||
|
||||
static JSClassID _httpd_class_id;
|
||||
static JSClassID _httpd_request_class_id;
|
||||
|
||||
typedef struct _http_user_data_t
|
||||
@ -538,12 +537,6 @@ static const char* _ext_to_content_type(const char* ext, bool use_fallback)
|
||||
return use_fallback ? "application/binary" : NULL;
|
||||
}
|
||||
|
||||
static void _httpd_finalizer(JSRuntime* runtime, JSValue value)
|
||||
{
|
||||
tf_http_t* http = JS_GetOpaque(value, _httpd_class_id);
|
||||
tf_http_destroy(http);
|
||||
}
|
||||
|
||||
static void _httpd_request_finalizer(JSRuntime* runtime, JSValue value)
|
||||
{
|
||||
tf_http_request_t* request = JS_GetOpaque(value, _httpd_request_class_id);
|
||||
@ -2362,16 +2355,7 @@ static const char* _httpd_read_file(tf_task_t* task, const char* path)
|
||||
|
||||
void tf_httpd_register(JSContext* context)
|
||||
{
|
||||
JS_NewClassID(&_httpd_class_id);
|
||||
JS_NewClassID(&_httpd_request_class_id);
|
||||
JSClassDef httpd_def = {
|
||||
.class_name = "Httpd",
|
||||
.finalizer = &_httpd_finalizer,
|
||||
};
|
||||
if (JS_NewClass(JS_GetRuntime(context), _httpd_class_id, &httpd_def) != 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to register Httpd.\n");
|
||||
}
|
||||
JSClassDef request_def = {
|
||||
.class_name = "Request",
|
||||
.finalizer = &_httpd_request_finalizer,
|
||||
@ -2382,14 +2366,19 @@ void tf_httpd_register(JSContext* context)
|
||||
}
|
||||
|
||||
JSValue global = JS_GetGlobalObject(context);
|
||||
JSValue httpd = JS_NewObjectClass(context, _httpd_class_id);
|
||||
JSValue httpd = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, httpd, "auth_query", JS_NewCFunction(context, _httpd_auth_query, "auth_query", 1));
|
||||
JS_SetPropertyStr(context, global, "httpd", httpd);
|
||||
JS_FreeValue(context, global);
|
||||
}
|
||||
|
||||
tf_http_t* tf_httpd_create(JSContext* context)
|
||||
{
|
||||
tf_task_t* task = tf_task_get(context);
|
||||
tf_ssb_t* ssb = tf_task_get_ssb(task);
|
||||
uv_loop_t* loop = tf_task_get_loop(task);
|
||||
tf_http_t* http = tf_http_create(loop);
|
||||
tf_http_set_trace(http, tf_task_get_trace(task));
|
||||
JS_SetOpaque(httpd, http);
|
||||
|
||||
int64_t http_port = 0;
|
||||
int64_t https_port = 0;
|
||||
@ -2454,10 +2443,6 @@ void tf_httpd_register(JSContext* context)
|
||||
|
||||
tf_http_add_handler(http, "/app/socket", _httpd_endpoint_app_socket, NULL, task);
|
||||
|
||||
JS_SetPropertyStr(context, httpd, "auth_query", JS_NewCFunction(context, _httpd_auth_query, "auth_query", 1));
|
||||
JS_SetPropertyStr(context, global, "httpd", httpd);
|
||||
JS_FreeValue(context, global);
|
||||
|
||||
if (http_port > 0 || *out_http_port_file)
|
||||
{
|
||||
httpd_listener_t* listener = tf_malloc(sizeof(httpd_listener_t));
|
||||
@ -2502,4 +2487,10 @@ void tf_httpd_register(JSContext* context)
|
||||
tf_free((char*)private_key);
|
||||
}
|
||||
}
|
||||
return http;
|
||||
}
|
||||
|
||||
void tf_httpd_destroy(tf_http_t* http)
|
||||
{
|
||||
tf_http_destroy(http);
|
||||
}
|
||||
|
Reference in New Issue
Block a user