Skip to content

Commit

Permalink
out buf update
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Jul 8, 2024
1 parent acc4ae5 commit 9aa287d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions include/cinatra/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,8 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
async_download(std::move(uri), std::move(filename), std::move(range)));
}

bool is_body_in_out_buf() const { return !out_buf_.empty(); }

void reset() {
if (!has_closed())
close_socket(*socket_);
Expand Down Expand Up @@ -1780,9 +1782,8 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
bool is_out_buf = !out_buf_.empty();
if (is_out_buf) {
if (content_len > 0 && out_buf_.size() < content_len) {
data.status = 404;
data.net_err = std::make_error_code(std::errc::no_buffer_space);
co_return data;
out_buf_ = {};
is_out_buf = false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test_cinatra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ TEST_CASE("test request with out buffer") {
auto result = async_simple::coro::syncAwait(ret);
std::cout << result.status << "\n";
std::cout << result.net_err.message() << "\n";
if (result.status == 404)
CHECK(result.net_err == std::errc::no_buffer_space);
CHECK(result.status < 400);
CHECK(!client.is_body_in_out_buf());
}

{
Expand Down

0 comments on commit 9aa287d

Please sign in to comment.