Work in progress HTTP server in C.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4676 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-12-13 23:59:11 +00:00
parent 0b47207949
commit 1d214f89ed
3 changed files with 283 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include "tests.h"
#include "http.h"
#include "log.h"
#include "mem.h"
#include "ssb.tests.h"
@ -11,6 +12,8 @@
#include <string.h>
#include <unistd.h>
#include <uv.h>
#if defined(_WIN32)
#define WIFEXITED(x) 1
#define WEXITSTATUS(x) (x)
@ -667,6 +670,38 @@ static void _test_b64(const tf_test_options_t* options)
unlink("out/test.js");
}
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));
assert(WEXITSTATUS(r) == 0);
#endif
}
static void _test_http_handler(tf_http_request_t* request)
{
tf_printf("HANDLER %d\n", request->phase);
}
static void _test_http(const tf_test_options_t* options)
{
uv_loop_t loop = { 0 };
uv_loop_init(&loop);
tf_http_t* http = tf_http_create(&loop);
tf_http_add_handler(http, NULL, _test_http_handler, NULL);
tf_http_listen(http, 23456);
uv_thread_t thread = { 0 };
uv_thread_create(&thread, _test_http_thread, NULL);
uv_run(&loop, UV_RUN_DEFAULT);
tf_http_destroy(http);
uv_loop_close(&loop);
uv_thread_join(&thread);
}
static void _tf_test_run(const tf_test_options_t* options, const char* name, void (*test)(const tf_test_options_t* options), bool opt_in)
{
bool specified = false;
@ -706,6 +741,7 @@ static void _tf_test_run(const tf_test_options_t* options, const char* name, voi
void tf_tests(const tf_test_options_t* options)
{
#if !TARGET_OS_IPHONE
_tf_test_run(options, "http", _test_http, false);
_tf_test_run(options, "ssb", tf_ssb_test_ssb, false);
_tf_test_run(options, "ssb_id", tf_ssb_test_id_conversion, false);
_tf_test_run(options, "ssb_following", tf_ssb_test_following, false);