From 7776532d3d8e81b0bd84f691ab91ef652d307cb9 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sat, 26 Aug 2023 12:24:18 +0800 Subject: [PATCH] fix tail --- .../ylt/thirdparty/cinatra/coro_http_client.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/ylt/thirdparty/cinatra/coro_http_client.hpp b/include/ylt/thirdparty/cinatra/coro_http_client.hpp index 9c7c40705..d44faeb9d 100644 --- a/include/ylt/thirdparty/cinatra/coro_http_client.hpp +++ b/include/ylt/thirdparty/cinatra/coro_http_client.hpp @@ -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; @@ -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; @@ -329,11 +333,13 @@ class coro_http_client { #endif // return body_, the user will own body's lifetime. - std::unique_ptr release_buf() { + auto release_buf() { if (body_.empty()) { - return std::unique_ptr(resp_chunk_str_.release()); + return std::unique_ptr( + resp_chunk_str_.release(), &free_simple_buffer); } - return std::unique_ptr(body_.release()); + return std::unique_ptr( + body_.release(), &free_simple_buffer); } // only make socket connet(or handshake) to the host @@ -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);