Commit 4b5179a5 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Fix bug in util::make_hostport

parent 8efccddc
......@@ -1147,31 +1147,6 @@ std::string dtos(double n) {
return utos(static_cast<int64_t>(n)) + "." + (f.size() == 1 ? "0" : "") + f;
}
std::string make_http_hostport(const StringRef &host, uint16_t port) {
if (port != 80 && port != 443) {
return make_hostport(host, port);
}
auto ipv6 = ipv6_numeric_addr(host.c_str());
std::string hostport;
hostport.resize(host.size() + (ipv6 ? 2 : 0));
auto p = &hostport[0];
if (ipv6) {
*p++ = '[';
}
p = std::copy_n(host.c_str(), host.size(), p);
if (ipv6) {
*p++ = ']';
}
return hostport;
}
StringRef make_http_hostport(BlockAllocator &balloc, const StringRef &host,
uint16_t port) {
if (port != 80 && port != 443) {
......@@ -1244,7 +1219,7 @@ StringRef make_hostport(BlockAllocator &balloc, const StringRef &host,
*p++ = ':';
std::copy(std::begin(serv), std::end(serv), p);
p = std::copy(std::begin(serv), std::end(serv), p);
*p = '\0';
......
......@@ -633,8 +633,6 @@ std::string format_duration(double t);
// Creates "host:port" string using given |host| and |port|. If
// |host| is numeric IPv6 address (e.g., ::1), it is enclosed by "["
// and "]". If |port| is 80 or 443, port part is omitted.
std::string make_http_hostport(const StringRef &host, uint16_t port);
StringRef make_http_hostport(BlockAllocator &balloc, const StringRef &host,
uint16_t port);
......
......@@ -502,12 +502,15 @@ void test_util_parse_config_str_list(void) {
}
void test_util_make_http_hostport(void) {
CU_ASSERT("localhost" ==
util::make_http_hostport(StringRef::from_lit("localhost"), 80));
BlockAllocator balloc(4096, 4096);
CU_ASSERT("localhost" == util::make_http_hostport(
balloc, StringRef::from_lit("localhost"), 80));
CU_ASSERT("[::1]" ==
util::make_http_hostport(StringRef::from_lit("::1"), 443));
CU_ASSERT("localhost:3000" ==
util::make_http_hostport(StringRef::from_lit("localhost"), 3000));
util::make_http_hostport(balloc, StringRef::from_lit("::1"), 443));
CU_ASSERT(
"localhost:3000" ==
util::make_http_hostport(balloc, StringRef::from_lit("localhost"), 3000));
}
void test_util_make_hostport(void) {
......@@ -515,6 +518,12 @@ void test_util_make_hostport(void) {
util::make_hostport(StringRef::from_lit("localhost"), 80));
CU_ASSERT("[::1]:443" ==
util::make_hostport(StringRef::from_lit("::1"), 443));
BlockAllocator balloc(4096, 4096);
CU_ASSERT("localhost:80" ==
util::make_hostport(balloc, StringRef::from_lit("localhost"), 80));
CU_ASSERT("[::1]:443" ==
util::make_hostport(balloc, StringRef::from_lit("::1"), 443));
}
void test_util_strifind(void) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment