Now we're uploading some data.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4682 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-12-20 23:58:28 +00:00
parent f4b6812675
commit c2f62cd8e0
3 changed files with 147 additions and 38 deletions

View File

@ -685,7 +685,15 @@ static void _test_http_thread(void* data)
{
#if defined(__linux__)
test_http_t* test = data;
int r = system("curl -v http://localhost:23456/");
int r = system("curl -v http://localhost:23456/404");
assert(WEXITSTATUS(r) == 0);
tf_printf("curl returned %d\n", WEXITSTATUS(r));
r = system("curl -v http://localhost:23456/hello");
assert(WEXITSTATUS(r) == 0);
tf_printf("curl returned %d\n", WEXITSTATUS(r));
r = system("curl -v --data 'hello world' http://localhost:23456/post");
assert(WEXITSTATUS(r) == 0);
tf_printf("curl returned %d\n", WEXITSTATUS(r));
@ -706,12 +714,27 @@ static void _test_http_handler(tf_http_request_t* request)
tf_http_respond(request, 200, headers, 1, k_payload, strlen(k_payload));
}
static void _test_http_handler_post(tf_http_request_t* request)
{
const void* body = NULL;
size_t size = tf_http_get_body(request, &body);
tf_printf("size = %zd body=%.*s\n", size, (int)size, (const char*)body);
const char* headers[] =
{
"Connection", "close",
};
const char* k_payload = "Hello, world!\n";
tf_http_respond(request, 200, headers, 1, k_payload, strlen(k_payload));
}
static void _test_http(const tf_test_options_t* options)
{
tf_printf("Starting http.\n");
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_add_handler(http, "/hello", _test_http_handler, NULL);
tf_http_add_handler(http, "/post", _test_http_handler_post, NULL);
tf_http_listen(http, 23456);
test_http_t test = { .loop = &loop };