forked from cory/tildefriends
Minor cleanup. Make http.c trace its callbacks.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4728 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -302,7 +302,7 @@ static void _httpd_websocket_callback(tf_http_request_t* request)
|
||||
_httpd_callback_internal(request, true);
|
||||
}
|
||||
|
||||
static JSValue _httpd_all(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
static JSValue _httpd_endpoint_all(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_http_t* http = JS_GetOpaque(this_val, _httpd_class_id);
|
||||
const char* pattern = JS_ToCString(context, argv[0]);
|
||||
@ -324,7 +324,7 @@ static JSValue _httpd_register_socket_handler(JSContext* context, JSValueConst t
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
static JSValue _httpd_start(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
static JSValue _httpd_endpoint_start(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
tf_http_t* http = JS_GetOpaque(this_val, _httpd_class_id);
|
||||
int port = 0;
|
||||
@ -356,13 +356,13 @@ static JSValue _httpd_set_http_redirect(JSContext* context, JSValueConst this_va
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
void _httpd_finalizer(JSRuntime* runtime, JSValue value)
|
||||
static void _httpd_finalizer(JSRuntime* runtime, JSValue value)
|
||||
{
|
||||
tf_http_t* http = JS_GetOpaque(value, _httpd_class_id);
|
||||
tf_http_destroy(http);
|
||||
}
|
||||
|
||||
void _httpd_request_finalizer(JSRuntime* runtime, JSValue value)
|
||||
static void _httpd_request_finalizer(JSRuntime* runtime, JSValue value)
|
||||
{
|
||||
tf_http_request_t* request = JS_GetOpaque(value, _httpd_request_class_id);
|
||||
tf_http_request_release(request);
|
||||
@ -377,7 +377,6 @@ static void _httpd_endpoint_trace(tf_http_request_t* request)
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_trace_t* trace = tf_task_get_trace(task);
|
||||
tf_trace_begin(trace, __func__);
|
||||
char* json = tf_trace_export(trace);
|
||||
const char* headers[] =
|
||||
{
|
||||
@ -386,7 +385,6 @@ static void _httpd_endpoint_trace(tf_http_request_t* request)
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, json, json ? strlen(json) : 0);
|
||||
tf_free(json);
|
||||
tf_trace_end(trace);
|
||||
}
|
||||
|
||||
static void _httpd_endpoint_mem(tf_http_request_t* request)
|
||||
@ -396,10 +394,6 @@ static void _httpd_endpoint_mem(tf_http_request_t* request)
|
||||
return;
|
||||
}
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_trace_t* trace = tf_task_get_trace(task);
|
||||
tf_trace_begin(trace, __func__);
|
||||
|
||||
char* response = NULL;
|
||||
size_t length = 0;
|
||||
|
||||
@ -423,8 +417,6 @@ static void _httpd_endpoint_mem(tf_http_request_t* request)
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, length);
|
||||
tf_free(response);
|
||||
|
||||
tf_trace_end(trace);
|
||||
}
|
||||
|
||||
static void _httpd_endpoint_disconnections(tf_http_request_t* request)
|
||||
@ -435,8 +427,6 @@ static void _httpd_endpoint_disconnections(tf_http_request_t* request)
|
||||
}
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_trace_t* trace = tf_task_get_trace(task);
|
||||
tf_trace_begin(trace, __func__);
|
||||
char* response = tf_task_get_disconnections(task);
|
||||
const char* headers[] =
|
||||
{
|
||||
@ -445,7 +435,6 @@ static void _httpd_endpoint_disconnections(tf_http_request_t* request)
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, response ? strlen(response) : 0);
|
||||
tf_free(response);
|
||||
tf_trace_end(trace);
|
||||
}
|
||||
|
||||
static void _httpd_endpoint_hitches(tf_http_request_t* request)
|
||||
@ -456,8 +445,6 @@ static void _httpd_endpoint_hitches(tf_http_request_t* request)
|
||||
}
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_trace_t* trace = tf_task_get_trace(task);
|
||||
tf_trace_begin(trace, __func__);
|
||||
char* response = tf_task_get_hitches(task);
|
||||
const char* headers[] =
|
||||
{
|
||||
@ -466,7 +453,6 @@ static void _httpd_endpoint_hitches(tf_http_request_t* request)
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, response ? strlen(response) : 0);
|
||||
tf_free(response);
|
||||
tf_trace_end(trace);
|
||||
}
|
||||
|
||||
static void _httpd_endpoint_debug(tf_http_request_t* request)
|
||||
@ -477,8 +463,6 @@ static void _httpd_endpoint_debug(tf_http_request_t* request)
|
||||
}
|
||||
|
||||
tf_task_t* task = request->user_data;
|
||||
tf_trace_t* trace = tf_task_get_trace(task);
|
||||
tf_trace_begin(trace, __func__);
|
||||
char* response = tf_task_get_debug(task);
|
||||
const char* headers[] =
|
||||
{
|
||||
@ -487,7 +471,6 @@ static void _httpd_endpoint_debug(tf_http_request_t* request)
|
||||
};
|
||||
tf_http_respond(request, 200, headers, tf_countof(headers) / 2, response, response ? strlen(response) : 0);
|
||||
tf_free(response);
|
||||
tf_trace_end(trace);
|
||||
}
|
||||
|
||||
void tf_httpd_register(JSContext* context)
|
||||
@ -518,6 +501,7 @@ void tf_httpd_register(JSContext* context)
|
||||
tf_task_t* task = tf_task_get(context);
|
||||
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);
|
||||
|
||||
tf_http_add_handler(http, "/debug", _httpd_endpoint_debug, task);
|
||||
@ -527,9 +511,9 @@ void tf_httpd_register(JSContext* context)
|
||||
tf_http_add_handler(http, "/trace", _httpd_endpoint_trace, task);
|
||||
|
||||
JS_SetPropertyStr(context, httpd, "handlers", JS_NewObject(context));
|
||||
JS_SetPropertyStr(context, httpd, "all", JS_NewCFunction(context, _httpd_all, "all", 2));
|
||||
JS_SetPropertyStr(context, httpd, "all", JS_NewCFunction(context, _httpd_endpoint_all, "all", 2));
|
||||
JS_SetPropertyStr(context, httpd, "registerSocketHandler", JS_NewCFunction(context, _httpd_register_socket_handler, "register_socket_handler", 2));
|
||||
JS_SetPropertyStr(context, httpd, "start", JS_NewCFunction(context, _httpd_start, "start", 2));
|
||||
JS_SetPropertyStr(context, httpd, "start", JS_NewCFunction(context, _httpd_endpoint_start, "start", 2));
|
||||
JS_SetPropertyStr(context, httpd, "set_http_redirect", JS_NewCFunction(context, _httpd_set_http_redirect, "set_http_redirect", 1));
|
||||
JS_SetPropertyStr(context, global, "httpd", httpd);
|
||||
JS_FreeValue(context, global);
|
||||
|
Reference in New Issue
Block a user