Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out buf update #612

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading