From 849da7c2ae5c1044e68da9bde1ec763bb27afd52 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Thu, 25 Apr 2024 13:45:40 +0800 Subject: [PATCH] fix --- .../ylt/standalone/cinatra/coro_http_response.hpp | 14 ++++++-------- src/coro_http/examples/example.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/ylt/standalone/cinatra/coro_http_response.hpp b/include/ylt/standalone/cinatra/coro_http_response.hpp index 0da9eba52..b3a55e46f 100644 --- a/include/ylt/standalone/cinatra/coro_http_response.hpp +++ b/include/ylt/standalone/cinatra/coro_http_response.hpp @@ -173,13 +173,6 @@ class coro_http_response { : resp_str.append(CONN_CLOSE_SV); } - if (content_view_.empty()) { - resp_str.append(content_); - } - else { - resp_str.append(content_view_); - } - append_header_str(resp_str, resp_headers_); if (!resp_header_span_.empty()) { @@ -187,7 +180,12 @@ class coro_http_response { } resp_str.append(CRCF); - resp_str.append(content_); + if (content_view_.empty()) { + resp_str.append(content_); + } + else { + resp_str.append(content_view_); + } } void append_header_str(auto &resp_str, auto &resp_headers) { diff --git a/src/coro_http/examples/example.cpp b/src/coro_http/examples/example.cpp index 09efa802a..4e05569b9 100644 --- a/src/coro_http/examples/example.cpp +++ b/src/coro_http/examples/example.cpp @@ -352,6 +352,16 @@ async_simple::coro::Lazy basic_usage() { response.set_status_and_content(status_type::ok, "ok"); }); + server.set_http_handler( + "/view", + [](coro_http_request &req, + coro_http_response &resp) -> async_simple::coro::Lazy { + resp.set_delay(true); + resp.set_status_and_content_view(status_type::ok, + req.get_body()); // no copy + co_await resp.get_conn()->reply(); + }); + person_t person{}; server.set_http_handler("/person", &person_t::foo, person); @@ -377,6 +387,11 @@ async_simple::coro::Lazy basic_usage() { assert(result.status == 200); assert(result.resp_body == "post string"); + result = co_await client.async_post("/view", "post string", + req_content_type::string); + assert(result.status == 200); + assert(result.resp_body == "post string"); + client.add_header("name", "tom"); client.add_header("age", "20"); result = co_await client.async_get("/headers");