diff --git a/cmake/build.cmake b/cmake/build.cmake index 91aae76a..0b5b9cec 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -21,7 +21,7 @@ endif() if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest") else () - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++20") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pthread -std=c++20") endif () # --------------------- Gcc diff --git a/include/cinatra/coro_http_response.hpp b/include/cinatra/coro_http_response.hpp index c0ea40e6..eb720765 100644 --- a/include/cinatra/coro_http_response.hpp +++ b/include/cinatra/coro_http_response.hpp @@ -144,8 +144,6 @@ class coro_http_response { void clear() { head_.clear(); content_.clear(); - head_.shrink_to_fit(); - content_.shrink_to_fit(); resp_headers_.clear(); resp_headers_sv_.clear(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0739a42d..4689b335 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,7 +27,7 @@ if(ENABLE_FILE_IO_URING) endif() if (UNIX) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pthread") endif() ## manual import diff --git a/tests/test_coro_http_server.cpp b/tests/test_coro_http_server.cpp index 9b2fb437..ac7ee48d 100644 --- a/tests/test_coro_http_server.cpp +++ b/tests/test_coro_http_server.cpp @@ -30,12 +30,11 @@ using namespace std::chrono_literals; TEST_CASE("coro_server example, will block") { return; // remove this line when you run the coro server. - cinatra::coro_http_server server(1, 9001); + cinatra::coro_http_server server(std::thread::hardware_concurrency(), 9001); server.set_http_handler( "/", [](coro_http_request &req, coro_http_response &resp) { // response in io thread. - std::cout << std::this_thread::get_id() << "\n"; - resp.set_keepalive(true); + std::this_thread::sleep_for(10ms); resp.set_status_and_content(cinatra::status_type::ok, "hello world"); }); @@ -43,17 +42,19 @@ TEST_CASE("coro_server example, will block") { "/coro", [](coro_http_request &req, coro_http_response &resp) -> async_simple::coro::Lazy { - std::cout << std::this_thread::get_id() << "\n"; - - co_await coro_io::post([&] { + co_await coro_io::post([&]() { // coroutine in other thread. - std::cout << std::this_thread::get_id() << "\n"; - resp.set_status(cinatra::status_type::ok); - resp.set_content("hello world in coro"); + std::this_thread::sleep_for(10ms); + resp.set_status_and_content(cinatra::status_type::ok, "hello world"); }); - std::cout << std::this_thread::get_id() << "\n"; co_return; }); + + server.set_http_handler( + "/echo", [](coro_http_request &req, coro_http_response &resp) { + // response in io thread. + resp.set_status_and_content(cinatra::status_type::ok, "hello world"); + }); server.sync_start(); CHECK(server.port() > 0); }