Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Apr 25, 2024
1 parent a7716ea commit 849da7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
14 changes: 6 additions & 8 deletions include/ylt/standalone/cinatra/coro_http_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,19 @@ 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()) {
append_header_str(resp_str, resp_header_span_);
}

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) {
Expand Down
15 changes: 15 additions & 0 deletions src/coro_http/examples/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ async_simple::coro::Lazy<void> basic_usage() {
response.set_status_and_content(status_type::ok, "ok");
});

server.set_http_handler<POST>(
"/view",
[](coro_http_request &req,
coro_http_response &resp) -> async_simple::coro::Lazy<void> {
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<GET>("/person", &person_t::foo, person);

Expand All @@ -377,6 +387,11 @@ async_simple::coro::Lazy<void> 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");
Expand Down

0 comments on commit 849da7c

Please sign in to comment.