Send a valid HTTP response and shutdown the connection.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4679 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-12-17 17:44:54 +00:00
parent 067f546580
commit 7b3a9e0f63
3 changed files with 71 additions and 13 deletions

View File

@ -674,14 +674,20 @@ static void _test_http_thread(void* data)
{
#if defined(__linux__)
int r = system("curl -v http://localhost:23456/");
tf_printf("curl returned %d\n", WEXITSTATUS(r));
*(int*)data = WEXITSTATUS(r);
assert(WEXITSTATUS(r) == 0);
tf_printf("curl returned %d\n", WEXITSTATUS(r));
#endif
}
static void _test_http_handler(tf_http_request_t* request)
{
tf_printf("HANDLER %d\n", request->phase);
const char* headers[] =
{
"Connection", "close",
};
tf_http_respond(request, 200, headers, 1, "Hello, world!", strlen("Hello, world!"));
}
static void _test_http(const tf_test_options_t* options)
@ -692,9 +698,14 @@ static void _test_http(const tf_test_options_t* options)
tf_http_add_handler(http, NULL, _test_http_handler, NULL);
tf_http_listen(http, 23456);
int result = -1;
uv_thread_t thread = { 0 };
uv_thread_create(&thread, _test_http_thread, NULL);
uv_run(&loop, UV_RUN_DEFAULT);
uv_thread_create(&thread, _test_http_thread, &result);
while (result == -1)
{
uv_run(&loop, UV_RUN_ONCE);
}
tf_printf("Done running.\n");
tf_http_destroy(http);
uv_loop_close(&loop);