diff --git a/tests/test_cinatra.cpp b/tests/test_cinatra.cpp index 9252b689..3131e09e 100644 --- a/tests/test_cinatra.cpp +++ b/tests/test_cinatra.cpp @@ -616,6 +616,7 @@ TEST_CASE("test basic http request") { << "\n"; } + // Setting up GET and POST handlers server.set_http_handler( "/", [&server](request &, response &res) mutable { res.set_status_and_content(status_type::ok, "hello world"); @@ -627,6 +628,20 @@ TEST_CASE("test basic http request") { res.set_status_and_content(status_type::ok, std::move(str)); }); + // Setting up PUT handler + server.set_http_handler( + "/", [&server](request &req, response &res) mutable { + std::string str(req.body()); + str.append(" put successfully"); + res.set_status_and_content(status_type::ok, std::move(str)); + }); + + // Setting up DELETE handler + server.set_http_handler( + "/", [&server](request &, response &res) mutable { + res.set_status_and_content(status_type::ok, "data deleted"); + }); + std::promise pr; std::future f = pr.get_future(); std::thread server_thread([&server, &pr]() { @@ -639,13 +654,28 @@ TEST_CASE("test basic http request") { coro_http_client client{}; std::string uri = "http://127.0.0.1:8090"; - resp_data result = async_simple::coro::syncAwait(client.async_get(uri)); - size_t size = result.resp_body.size(); + + // Testing PUT method + resp_data result = async_simple::coro::syncAwait(client.async_request( + uri, http_method::PUT, + req_context{.content = "data for put"})); + CHECK(result.resp_body == "data for put put successfully"); + + // Testing DELETE method + result = async_simple::coro::syncAwait(client.async_request( + uri, http_method::DEL, req_context{})); + CHECK(result.resp_body == "data deleted"); + + // Testing GET method again after DELETE + result = async_simple::coro::syncAwait(client.async_get(uri)); CHECK(result.resp_body == "hello world"); + + size_t size = result.resp_body.size(); auto buf = client.release_buf(); CHECK(size == strlen(buf.data())); CHECK(buf == "hello world"); + // Rest of the POST tests result = async_simple::coro::syncAwait(client.async_post( uri, "async post hello coro_http_client", req_content_type::string)); CHECK(result.resp_body ==