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

[coro_http_client][fix]fix tail #429

Merged
merged 1 commit into from
Aug 26, 2023
Merged
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
14 changes: 10 additions & 4 deletions include/ylt/thirdparty/cinatra/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ struct multipart_t {
size_t size = 0;
};

inline void free_simple_buffer(char *ptr) { ::free(ptr); }

class simple_buffer {
public:
inline static constexpr size_t sbuf_init_size = 4096;
Expand Down Expand Up @@ -150,6 +152,8 @@ class simple_buffer {

size_t size() const { return m_size; }

void increase_size(size_t size) { m_size += size; }

char *release() {
char *tmp = m_data;
m_size = 0;
Expand Down Expand Up @@ -329,11 +333,13 @@ class coro_http_client {
#endif

// return body_, the user will own body's lifetime.
std::unique_ptr<char[]> release_buf() {
auto release_buf() {
if (body_.empty()) {
return std::unique_ptr<char[]>(resp_chunk_str_.release());
return std::unique_ptr<char[], decltype(&free_simple_buffer)>(
resp_chunk_str_.release(), &free_simple_buffer);
}
return std::unique_ptr<char[]>(body_.release());
return std::unique_ptr<char[], decltype(&free_simple_buffer)>(
body_.release(), &free_simple_buffer);
}

// only make socket connet(or handshake) to the host
Expand Down Expand Up @@ -1309,7 +1315,7 @@ class coro_http_client {
ec) {
break;
}

body_.increase_size(size_to_read);
// Now get entire content, additional data will discard.
co_await handle_entire_content(data, content_len, is_ranges, ctx);
} while (0);
Expand Down
Loading