From e6fd92858ac36e4b6e39e6bf8515a005e058669d Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Mon, 20 Jul 2026 10:37:26 -0600 Subject: [PATCH] refactor: use the transfer algorithms and source/sink types from boost.http push_to and the source/sink type-erased wrappers (any_buffer_source, any_buffer_sink, any_read_source) plus the BufferSource concept moved from capy to boost.http. Point burl's includes and qualifications at their new home: , , and http:: instead of capy:: for those symbols. --- doc/modules/ROOT/pages/2.guide/2n.extending.adoc | 2 +- example/nlohmann_json.cpp | 2 +- include/boost/burl/any_request_body.hpp | 8 ++++---- include/boost/burl/detail/parser.hpp | 2 +- include/boost/burl/request_body.hpp | 4 ++-- include/boost/burl/response.hpp | 8 ++++---- src/client.cpp | 2 +- src/detail/send_file.cpp | 4 ++-- src/detail/send_file.hpp | 4 ++-- src/file.cpp | 8 ++++---- src/json.cpp | 2 +- src/multipart_form.cpp | 4 ++-- src/response.cpp | 8 ++++---- src/string.cpp | 4 ++-- src/urlencoded_form.cpp | 4 ++-- test/unit/body_test.hpp | 12 ++++++------ test/unit/detail/send_file.cpp | 12 ++++++------ test/unit/urlencoded_form.cpp | 8 ++++---- 18 files changed, 49 insertions(+), 49 deletions(-) diff --git a/doc/modules/ROOT/pages/2.guide/2n.extending.adoc b/doc/modules/ROOT/pages/2.guide/2n.extending.adoc index 3d94908..a199bd9 100644 --- a/doc/modules/ROOT/pages/2.guide/2n.extending.adoc +++ b/doc/modules/ROOT/pages/2.guide/2n.extending.adoc @@ -27,7 +27,7 @@ struct MyRequestBody { std::optional content_type() const; std::optional content_length() const; - capy::io_task<> write(capy::any_buffer_sink& sink) const; + capy::io_task<> write(http::any_buffer_sink& sink) const; }; ---- diff --git a/example/nlohmann_json.cpp b/example/nlohmann_json.cpp index 5eec092..9bbf009 100644 --- a/example/nlohmann_json.cpp +++ b/example/nlohmann_json.cpp @@ -49,7 +49,7 @@ tag_invoke(burl::body_from_tag, const nlohmann::json& value) } capy::io_task<> - write(capy::any_buffer_sink& sink) const + write(http::any_buffer_sink& sink) const { auto [ec, n] = co_await sink.write_eof(capy::make_buffer(text_)); co_return { ec }; diff --git a/include/boost/burl/any_request_body.hpp b/include/boost/burl/any_request_body.hpp index 582a332..5aaef3e 100644 --- a/include/boost/burl/any_request_body.hpp +++ b/include/boost/burl/any_request_body.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include @@ -59,7 +59,7 @@ class any_request_body content_length() const = 0; virtual capy::io_task<> - write(capy::any_buffer_sink& sink) const = 0; + write(http::any_buffer_sink& sink) const = 0; }; template @@ -85,7 +85,7 @@ class any_request_body } capy::io_task<> - write(capy::any_buffer_sink& sink) const override + write(http::any_buffer_sink& sink) const override { return body.write(sink); } @@ -215,7 +215,7 @@ class any_request_body @return An awaitable yielding `(error_code)`. */ capy::io_task<> - write(capy::any_buffer_sink& sink) const + write(http::any_buffer_sink& sink) const { return impl_->write(sink); } diff --git a/include/boost/burl/detail/parser.hpp b/include/boost/burl/detail/parser.hpp index 0477c38..35390ef 100644 --- a/include/boost/burl/detail/parser.hpp +++ b/include/boost/burl/detail/parser.hpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/boost/burl/request_body.hpp b/include/boost/burl/request_body.hpp index 220a398..f752223 100644 --- a/include/boost/burl/request_body.hpp +++ b/include/boost/burl/request_body.hpp @@ -12,7 +12,7 @@ #include -#include +#include #include #include @@ -44,7 +44,7 @@ namespace burl @ref body_from_tag. */ template -concept RequestBody = requires(T const& t, capy::any_buffer_sink& sink) { +concept RequestBody = requires(T const& t, http::any_buffer_sink& sink) { { t.content_type() } -> std::same_as>; { t.content_length() } -> std::same_as>; { t.write(sink) } -> std::same_as>; diff --git a/include/boost/burl/response.hpp b/include/boost/burl/response.hpp index e4ddae4..139b455 100644 --- a/include/boost/burl/response.hpp +++ b/include/boost/burl/response.hpp @@ -16,8 +16,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -416,7 +416,7 @@ class response @see @ref as_read_source. */ BOOST_BURL_DECL - capy::any_buffer_source + http::any_buffer_source as_buffer_source() &; /** Return a read source for reading the body. @@ -431,7 +431,7 @@ class response @see @ref as_buffer_source. */ BOOST_BURL_DECL - capy::any_read_source + http::any_read_source as_read_source() &; }; diff --git a/src/client.cpp b/src/client.cpp index 001c60a..4c6bf8e 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -265,7 +265,7 @@ client::execute_impl( sr.reset(&stream, &headers); if(request.body.has_value()) { - capy::any_buffer_sink sink(&sr); + http::any_buffer_sink sink(&sr); if(auto [wec] = co_await request.body.write(sink); wec) co_return { wec, {} }; } diff --git a/src/detail/send_file.cpp b/src/detail/send_file.cpp index 26dbf8a..16f1f4d 100644 --- a/src/detail/send_file.cpp +++ b/src/detail/send_file.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include @@ -29,7 +29,7 @@ namespace detail capy::io_task<> send_file( - capy::any_buffer_sink& sink, + http::any_buffer_sink& sink, std::filesystem::path const& path, std::uint64_t size, bool call_eof) diff --git a/src/detail/send_file.hpp b/src/detail/send_file.hpp index 74ca388..ab59dee 100644 --- a/src/detail/send_file.hpp +++ b/src/detail/send_file.hpp @@ -10,7 +10,7 @@ #ifndef BOOST_BURL_SRC_DETAIL_SEND_FILE_HPP #define BOOST_BURL_SRC_DETAIL_SEND_FILE_HPP -#include +#include #include #include @@ -32,7 +32,7 @@ namespace detail // with error::file_changed if the file no longer holds `size` bytes. capy::io_task<> send_file( - capy::any_buffer_sink& sink, + http::any_buffer_sink& sink, std::filesystem::path const& path, std::uint64_t size, bool call_eof = false); diff --git a/src/file.cpp b/src/file.cpp index 156aa29..306f1c0 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -12,8 +12,8 @@ #include "detail/send_file.hpp" #include -#include -#include +#include +#include #include #include #include @@ -61,7 +61,7 @@ class file_body } capy::io_task<> - write(capy::any_buffer_sink& sink) const + write(http::any_buffer_sink& sink) const { return detail::send_file(sink, path_, size_, true); } @@ -94,7 +94,7 @@ tag_invoke( } auto src = resp.as_buffer_source(); - auto [ec, n] = co_await capy::push_to(src, f); + auto [ec, n] = co_await http::push_to(src, f); co_return { ec, std::move(dest) }; } diff --git a/src/json.cpp b/src/json.cpp index a4b9a6e..91b445a 100644 --- a/src/json.cpp +++ b/src/json.cpp @@ -52,7 +52,7 @@ class json_body } capy::io_task<> - write(capy::any_buffer_sink& sink) const + write(http::any_buffer_sink& sink) const { json::serializer sr; sr.reset(&value_); diff --git a/src/multipart_form.cpp b/src/multipart_form.cpp index 0446b38..4c52aaf 100644 --- a/src/multipart_form.cpp +++ b/src/multipart_form.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include @@ -173,7 +173,7 @@ class multipart_form::body } capy::io_task<> - write(capy::any_buffer_sink& sink) const + write(http::any_buffer_sink& sink) const { using capy::make_buffer; diff --git a/src/response.cpp b/src/response.cpp index 15f85fd..db0f2c5 100644 --- a/src/response.cpp +++ b/src/response.cpp @@ -87,16 +87,16 @@ response::as_view() & co_return std::move(body); } -capy::any_buffer_source +http::any_buffer_source response::as_buffer_source() & { - return capy::any_buffer_source(&parser_); + return http::any_buffer_source(&parser_); } -capy::any_read_source +http::any_read_source response::as_read_source() & { - return capy::any_read_source(&parser_); + return http::any_read_source(&parser_); } } // namespace burl diff --git a/src/string.cpp b/src/string.cpp index 90e8184..a4dc2a5 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -48,7 +48,7 @@ class string_body } capy::io_task<> - write(capy::any_buffer_sink& sink) const + write(http::any_buffer_sink& sink) const { auto [ec, n] = co_await sink.write_eof( @@ -80,7 +80,7 @@ class string_view_body } capy::io_task<> - write(capy::any_buffer_sink& sink) const + write(http::any_buffer_sink& sink) const { auto [ec, n] = co_await sink.write_eof( capy::make_buffer(body_)); diff --git a/src/urlencoded_form.cpp b/src/urlencoded_form.cpp index 48cc257..51ff6c5 100644 --- a/src/urlencoded_form.cpp +++ b/src/urlencoded_form.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -78,7 +78,7 @@ class urlencoded_form::body } capy::io_task<> - write(capy::any_buffer_sink& sink) const + write(http::any_buffer_sink& sink) const { auto [ec, n] = co_await sink.write_eof( capy::make_buffer(std::string_view(body_))); diff --git a/test/unit/body_test.hpp b/test/unit/body_test.hpp index ce490ad..6d37d8a 100644 --- a/test/unit/body_test.hpp +++ b/test/unit/body_test.hpp @@ -13,9 +13,9 @@ #include #include -#include +#include #include -#include +#include #include #include @@ -37,8 +37,8 @@ check_body( BOOST_TEST(body.has_value()); capy::test::fuse f; auto r = f.armed([&](capy::test::fuse& f) -> capy::task<> { - capy::test::buffer_sink bs(f); - capy::any_buffer_sink sink(&bs); + http::test::buffer_sink bs(f); + http::any_buffer_sink sink(&bs); auto [ec] = co_await body.write(sink); if(ec) @@ -57,8 +57,8 @@ check_io_body( { corosio::io_context ioc; std::error_code ec; - capy::test::buffer_sink bs; - capy::any_buffer_sink sink(&bs); + http::test::buffer_sink bs; + http::any_buffer_sink sink(&bs); capy::run_async( ioc.get_executor(), [&](capy::io_result<> res) {ec = res.ec; }) diff --git a/test/unit/detail/send_file.cpp b/test/unit/detail/send_file.cpp index 9d41975..b760198 100644 --- a/test/unit/detail/send_file.cpp +++ b/test/unit/detail/send_file.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include "../temp_file.hpp" @@ -32,11 +32,11 @@ class send_file_test static std::error_code run(std::filesystem::path const& path, std::uint64_t size, - capy::test::buffer_sink& bs) + http::test::buffer_sink& bs) { corosio::io_context ioc; std::error_code ret; - capy::any_buffer_sink sink(&bs); + http::any_buffer_sink sink(&bs); capy::run_async( ioc.get_executor(), [&](capy::io_result<> r) { ret = r.ec; }) @@ -52,7 +52,7 @@ class send_file_test std::string const contents = "hello file body"; temp_file tmp(contents); - capy::test::buffer_sink bs; + http::test::buffer_sink bs; auto ec = run(tmp.path, contents.size(), bs); BOOST_TEST(!ec); @@ -65,7 +65,7 @@ class send_file_test std::string const contents = "hello"; temp_file tmp(contents); - capy::test::buffer_sink bs; + http::test::buffer_sink bs; auto ec = run(tmp.path, contents.size() + 10, bs); BOOST_TEST(ec == error::file_changed); @@ -77,7 +77,7 @@ class send_file_test std::string const contents = "hello file body"; temp_file tmp(contents); - capy::test::buffer_sink bs; + http::test::buffer_sink bs; auto ec = run(tmp.path, 5, bs); BOOST_TEST(!ec); diff --git a/test/unit/urlencoded_form.cpp b/test/unit/urlencoded_form.cpp index 8b1bb8a..acb80d3 100644 --- a/test/unit/urlencoded_form.cpp +++ b/test/unit/urlencoded_form.cpp @@ -13,9 +13,9 @@ #include #include -#include +#include #include -#include +#include #include #include "test_suite.hpp" @@ -53,8 +53,8 @@ struct urlencoded_form_test capy::test::fuse().armed( [&](capy::test::fuse& f) -> capy::task { - capy::test::buffer_sink bs(f); - capy::any_buffer_sink sink(&bs); + http::test::buffer_sink bs(f); + http::any_buffer_sink sink(&bs); auto [ec] = co_await body.write(sink); if(ec)