Skip to content
Merged

Work #27

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
4 changes: 2 additions & 2 deletions include/boost/burl/detail/connection_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions include/boost/burl/test/detail/buffer_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t>
Expand Down
53 changes: 18 additions & 35 deletions src/detail/connection_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <boost/burl/error.hpp>

#include "effective_port.hpp"
#include "http_tunnel.hpp"
#include "socks5_tunnel.hpp"

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -104,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<std::size_t>
Expand Down Expand Up @@ -149,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<std::size_t>
Expand Down Expand Up @@ -186,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<std::size_t>
Expand Down
39 changes: 39 additions & 0 deletions src/detail/effective_port.cpp
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions src/detail/effective_port.hpp
Original file line number Diff line number Diff line change
@@ -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 <boost/url/url_view.hpp>

#include <string_view>

namespace boost
{
namespace burl
{
namespace detail
{

std::string_view
effective_port(const urls::url_view& url) noexcept;

} // namespace detail
} // namespace burl
} // namespace boost

#endif
62 changes: 62 additions & 0 deletions test/unit/detail/effective_port.cpp
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions test/unit/test/detail/buffer_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}());
}

Expand Down
Loading