From c951b4bb95296a894e69d3f7458ffb1065420244 Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Thu, 18 Jun 2026 11:03:50 +0000 Subject: [PATCH 1/2] connection_pool: extract effective_port into its own header --- src/detail/connection_pool.cpp | 19 +-------- src/detail/effective_port.cpp | 39 ++++++++++++++++++ src/detail/effective_port.hpp | 31 +++++++++++++++ test/unit/detail/effective_port.cpp | 62 +++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+), 18 deletions(-) create mode 100644 src/detail/effective_port.cpp create mode 100644 src/detail/effective_port.hpp create mode 100644 test/unit/detail/effective_port.cpp diff --git a/src/detail/connection_pool.cpp b/src/detail/connection_pool.cpp index 4592016..735a112 100644 --- a/src/detail/connection_pool.cpp +++ b/src/detail/connection_pool.cpp @@ -11,6 +11,7 @@ #include +#include "effective_port.hpp" #include "http_tunnel.hpp" #include "socks5_tunnel.hpp" @@ -39,24 +40,6 @@ namespace detail namespace { -std::string_view -effective_port(const urls::url_view& url) -{ - if(url.has_port()) - return url.port(); - - if(url.scheme() == "https") - return "443"; - - if(url.scheme() == "http") - return "80"; - - if(url.scheme() == "socks5" || url.scheme() == "socks5h") - return "1080"; - - return {}; -} - std::string origin(urls::url_view url) { diff --git a/src/detail/effective_port.cpp b/src/detail/effective_port.cpp new file mode 100644 index 0000000..0245c30 --- /dev/null +++ b/src/detail/effective_port.cpp @@ -0,0 +1,39 @@ +// +// Copyright (c) 2026 Mohammad Nejati +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/cppalliance/burl +// + +#include "effective_port.hpp" + +namespace boost +{ +namespace burl +{ +namespace detail +{ + +std::string_view +effective_port(const urls::url_view& url) noexcept +{ + if(url.has_port()) + return url.port(); + + if(url.scheme() == "https") + return "443"; + + if(url.scheme() == "http") + return "80"; + + if(url.scheme() == "socks5" || url.scheme() == "socks5h") + return "1080"; + + return {}; +} + +} // namespace detail +} // namespace burl +} // namespace boost diff --git a/src/detail/effective_port.hpp b/src/detail/effective_port.hpp new file mode 100644 index 0000000..6bfa586 --- /dev/null +++ b/src/detail/effective_port.hpp @@ -0,0 +1,31 @@ +// +// Copyright (c) 2026 Mohammad Nejati +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/cppalliance/burl +// + +#ifndef BOOST_BURL_SRC_DETAIL_EFFECTIVE_PORT_HPP +#define BOOST_BURL_SRC_DETAIL_EFFECTIVE_PORT_HPP + +#include + +#include + +namespace boost +{ +namespace burl +{ +namespace detail +{ + +std::string_view +effective_port(const urls::url_view& url) noexcept; + +} // namespace detail +} // namespace burl +} // namespace boost + +#endif diff --git a/test/unit/detail/effective_port.cpp b/test/unit/detail/effective_port.cpp new file mode 100644 index 0000000..2362f47 --- /dev/null +++ b/test/unit/detail/effective_port.cpp @@ -0,0 +1,62 @@ +// +// Copyright (c) 2026 Mohammad Nejati +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/cppalliance/burl +// + +// Test that header file is self-contained. +#include "src/detail/effective_port.hpp" + +#include "test_suite.hpp" + +namespace boost +{ +namespace burl +{ +namespace detail +{ + +class effective_port_test +{ +public: + void + testExplicitPort() + { + BOOST_TEST_EQ(effective_port("http://example.com:8080"), "8080"); + BOOST_TEST_EQ(effective_port("ftp://example.com:21"), "21"); + BOOST_TEST_EQ(effective_port("http://example.com:80"), "80"); + } + + void + testDefaultPort() + { + BOOST_TEST_EQ(effective_port("http://example.com"), "80"); + BOOST_TEST_EQ(effective_port("https://example.com"), "443"); + BOOST_TEST_EQ(effective_port("socks5://example.com"), "1080"); + BOOST_TEST_EQ(effective_port("socks5h://example.com"), "1080"); + } + + void + testUnknownScheme() + { + BOOST_TEST_EQ(effective_port("ftp://example.com"), ""); + BOOST_TEST_EQ(effective_port("ws://example.com"), ""); + } + + void + run() + { + testExplicitPort(); + testDefaultPort(); + testUnknownScheme(); + } +}; + +TEST_SUITE(effective_port_test, "boost.burl.detail.effective_port"); + +} // namespace detail +} // namespace burl +} // namespace boost From 276043e6232c3fd6e4d9dc45dc5b17f3a7432b78 Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Thu, 18 Jun 2026 11:07:38 +0000 Subject: [PATCH 2/2] connection_pool: comment out connection shutdown interface --- include/boost/burl/detail/connection_pool.hpp | 4 +-- .../burl/test/detail/buffer_connection.hpp | 10 +++--- src/detail/connection_pool.cpp | 34 +++++++++---------- test/unit/test/detail/buffer_connection.cpp | 6 ++-- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/include/boost/burl/detail/connection_pool.hpp b/include/boost/burl/detail/connection_pool.hpp index 347e998..14825e4 100644 --- a/include/boost/burl/detail/connection_pool.hpp +++ b/include/boost/burl/detail/connection_pool.hpp @@ -59,8 +59,8 @@ class connection virtual bool is_open() const noexcept = 0; - virtual capy::io_task<> - shutdown() = 0; + // virtual capy::io_task<> + // shutdown() = 0; virtual ~connection() = default; diff --git a/include/boost/burl/test/detail/buffer_connection.hpp b/include/boost/burl/test/detail/buffer_connection.hpp index a5b2fbb..0d54d7c 100644 --- a/include/boost/burl/test/detail/buffer_connection.hpp +++ b/include/boost/burl/test/detail/buffer_connection.hpp @@ -54,11 +54,11 @@ class buffer_connection final : public burl::detail::connection return true; } - capy::io_task<> - shutdown() override - { - co_return {}; - } + // capy::io_task<> + // shutdown() override + // { + // co_return {}; + // } private: capy::io_task diff --git a/src/detail/connection_pool.cpp b/src/detail/connection_pool.cpp index 735a112..6b46968 100644 --- a/src/detail/connection_pool.cpp +++ b/src/detail/connection_pool.cpp @@ -87,12 +87,12 @@ class tcp_connection final : public connection return socket_.is_open(); } - capy::io_task<> - shutdown() override - { - socket_.shutdown(corosio::shutdown_both); - co_return {}; - } + // capy::io_task<> + // shutdown() override + // { + // socket_.shutdown(corosio::shutdown_both); + // co_return {}; + // } private: capy::io_task @@ -132,11 +132,11 @@ class tls_connection final : public connection return socket_.is_open(); } - capy::io_task<> - shutdown() override - { - return stream_.shutdown(); - } + // capy::io_task<> + // shutdown() override + // { + // return stream_.shutdown(); + // } private: capy::io_task @@ -169,12 +169,12 @@ class stream_connection final : public connection return open_; } - capy::io_task<> - shutdown() override - { - open_ = false; - co_return {}; - } + // capy::io_task<> + // shutdown() override + // { + // open_ = false; + // co_return {}; + // } private: capy::io_task diff --git a/test/unit/test/detail/buffer_connection.cpp b/test/unit/test/detail/buffer_connection.cpp index f6e8984..f760b9a 100644 --- a/test/unit/test/detail/buffer_connection.cpp +++ b/test/unit/test/detail/buffer_connection.cpp @@ -151,9 +151,9 @@ struct buffer_connection_test BOOST_TEST(conn.is_open()); // shutdown completes without error and is a no-op. - auto [sec] = co_await conn.shutdown(); - BOOST_TEST(!sec); - BOOST_TEST(conn.is_open()); + // auto [sec] = co_await conn.shutdown(); + // BOOST_TEST(!sec); + // BOOST_TEST(conn.is_open()); }()); }