File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
src/network/http/v2/client Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -127,7 +127,17 @@ namespace network {
127
127
}
128
128
129
129
std::uint16_t port () const {
130
- assert (destination_.port ());
130
+ assert (destination_.scheme ());
131
+ assert ((string_type (*destination_.scheme ()) == " http" ) ||
132
+ (string_type (*destination_.scheme ()) == " https" ));
133
+ if (!destination_.port ()) {
134
+ if (string_type (*destination_.scheme ()) == " http" ) {
135
+ return 80 ;
136
+ }
137
+ else if (string_type (*destination_.scheme ()) == " https" ) {
138
+ return 443 ;
139
+ }
140
+ }
131
141
return *destination_.port <std::uint16_t >();
132
142
}
133
143
Original file line number Diff line number Diff line change @@ -123,3 +123,18 @@ TEST(request_test, remove_duplicate_headers) {
123
123
++headers_it;
124
124
ASSERT_TRUE (headers_it == std::end (headers));
125
125
}
126
+
127
+ TEST (request_test, port) {
128
+ http::request instance{network::uri{" http://www.example.com:8000/path/to/resource/index.html" }};
129
+ ASSERT_EQ (8000 , instance.port ());
130
+ }
131
+
132
+ TEST (request_test, http_default_port) {
133
+ http::request instance{network::uri{" http://www.example.com/path/to/resource/index.html" }};
134
+ ASSERT_EQ (80 , instance.port ());
135
+ }
136
+
137
+ TEST (request_test, https_default_port) {
138
+ http::request instance{network::uri{" https://www.example.com/path/to/resource/index.html" }};
139
+ ASSERT_EQ (443 , instance.port ());
140
+ }
You can’t perform that action at this time.
0 commit comments