Skip to content

Commit

Permalink
fix request (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Feb 5, 2024
1 parent 018a180 commit c8fe85d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/cinatra/coro_http_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class coro_http_connection
}

response_.clear();
request_.clear();
buffers_.clear();
body_.clear();
resp_str_.clear();
Expand Down
2 changes: 2 additions & 0 deletions include/cinatra/coro_http_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ class coro_http_request {

bool has_session() { return !cached_session_id_.empty(); }

void clear() { body_ = {}; }

std::unordered_map<std::string, std::string> params_;
std::smatch matches_;

Expand Down
26 changes: 26 additions & 0 deletions tests/test_coro_http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,32 @@ TEST_CASE("test redirect") {
}
}

TEST_CASE("test post") {
cinatra::coro_http_server server(1, 9001);
server.set_http_handler<cinatra::GET, cinatra::POST>(
"/echo",
[](coro_http_request &req,
coro_http_response &resp) -> async_simple::coro::Lazy<void> {
resp.set_status_and_content(status_type::ok,
std::string(req.get_body()));
co_return;
});

server.async_start();
std::this_thread::sleep_for(200ms);

coro_http_client client{};
std::string str = "test";
auto r =
client.post("http://127.0.0.1:9001/echo", str, req_content_type::text);
CHECK(r.status == 200);
CHECK(r.resp_body == "test");

r = client.post("/echo", "", req_content_type::text);
CHECK(r.status == 200);
CHECK(r.resp_body == "");
}

TEST_CASE("test multiple download") {
coro_http_server server(1, 9001);
server.set_http_handler<GET>(
Expand Down

0 comments on commit c8fe85d

Please sign in to comment.