Skip to content

Commit 5e68836

Browse files
committed
Updated requests test to check the port number.
1 parent d9174e6 commit 5e68836

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

http/src/network/http/v2/client/request.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,17 @@ namespace network {
127127
}
128128

129129
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+
}
131141
return *destination_.port<std::uint16_t>();
132142
}
133143

http/test/v2/client/request_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,18 @@ TEST(request_test, remove_duplicate_headers) {
123123
++headers_it;
124124
ASSERT_TRUE(headers_it == std::end(headers));
125125
}
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+
}

0 commit comments

Comments
 (0)