File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111
1212#include < boost/burl/error.hpp>
1313
14+ #include " effective_port.hpp"
1415#include " http_tunnel.hpp"
1516#include " socks5_tunnel.hpp"
1617
@@ -39,24 +40,6 @@ namespace detail
3940namespace
4041{
4142
42- std::string_view
43- effective_port (const urls::url_view& url)
44- {
45- if (url.has_port ())
46- return url.port ();
47-
48- if (url.scheme () == " https" )
49- return " 443" ;
50-
51- if (url.scheme () == " http" )
52- return " 80" ;
53-
54- if (url.scheme () == " socks5" || url.scheme () == " socks5h" )
55- return " 1080" ;
56-
57- return {};
58- }
59-
6043std::string
6144origin (urls::url_view url)
6245{
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (c) 2026 Mohammad Nejati
3+ //
4+ // Distributed under the Boost Software License, Version 1.0. (See accompanying
5+ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+ //
7+ // Official repository: https://github.com/cppalliance/burl
8+ //
9+
10+ #include " effective_port.hpp"
11+
12+ namespace boost
13+ {
14+ namespace burl
15+ {
16+ namespace detail
17+ {
18+
19+ std::string_view
20+ effective_port (const urls::url_view& url) noexcept
21+ {
22+ if (url.has_port ())
23+ return url.port ();
24+
25+ if (url.scheme () == " https" )
26+ return " 443" ;
27+
28+ if (url.scheme () == " http" )
29+ return " 80" ;
30+
31+ if (url.scheme () == " socks5" || url.scheme () == " socks5h" )
32+ return " 1080" ;
33+
34+ return {};
35+ }
36+
37+ } // namespace detail
38+ } // namespace burl
39+ } // namespace boost
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (c) 2026 Mohammad Nejati
3+ //
4+ // Distributed under the Boost Software License, Version 1.0. (See accompanying
5+ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+ //
7+ // Official repository: https://github.com/cppalliance/burl
8+ //
9+
10+ #ifndef BOOST_BURL_SRC_DETAIL_EFFECTIVE_PORT_HPP
11+ #define BOOST_BURL_SRC_DETAIL_EFFECTIVE_PORT_HPP
12+
13+ #include < boost/url/url_view.hpp>
14+
15+ #include < string_view>
16+
17+ namespace boost
18+ {
19+ namespace burl
20+ {
21+ namespace detail
22+ {
23+
24+ std::string_view
25+ effective_port (const urls::url_view& url) noexcept ;
26+
27+ } // namespace detail
28+ } // namespace burl
29+ } // namespace boost
30+
31+ #endif
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (c) 2026 Mohammad Nejati
3+ //
4+ // Distributed under the Boost Software License, Version 1.0. (See accompanying
5+ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+ //
7+ // Official repository: https://github.com/cppalliance/burl
8+ //
9+
10+ // Test that header file is self-contained.
11+ #include " src/detail/effective_port.hpp"
12+
13+ #include " test_suite.hpp"
14+
15+ namespace boost
16+ {
17+ namespace burl
18+ {
19+ namespace detail
20+ {
21+
22+ class effective_port_test
23+ {
24+ public:
25+ void
26+ testExplicitPort ()
27+ {
28+ BOOST_TEST_EQ (effective_port (" http://example.com:8080" ), " 8080" );
29+ BOOST_TEST_EQ (effective_port (" ftp://example.com:21" ), " 21" );
30+ BOOST_TEST_EQ (effective_port (" http://example.com:80" ), " 80" );
31+ }
32+
33+ void
34+ testDefaultPort ()
35+ {
36+ BOOST_TEST_EQ (effective_port (" http://example.com" ), " 80" );
37+ BOOST_TEST_EQ (effective_port (" https://example.com" ), " 443" );
38+ BOOST_TEST_EQ (effective_port (" socks5://example.com" ), " 1080" );
39+ BOOST_TEST_EQ (effective_port (" socks5h://example.com" ), " 1080" );
40+ }
41+
42+ void
43+ testUnknownScheme ()
44+ {
45+ BOOST_TEST_EQ (effective_port (" ftp://example.com" ), " " );
46+ BOOST_TEST_EQ (effective_port (" ws://example.com" ), " " );
47+ }
48+
49+ void
50+ run ()
51+ {
52+ testExplicitPort ();
53+ testDefaultPort ();
54+ testUnknownScheme ();
55+ }
56+ };
57+
58+ TEST_SUITE (effective_port_test, " boost.burl.detail.effective_port" );
59+
60+ } // namespace detail
61+ } // namespace burl
62+ } // namespace boost
You can’t perform that action at this time.
0 commit comments