Skip to content

Commit a1baf87

Browse files
committed
fix: FillHost adapt ipv6 (#683)
1 parent 9a3c19c commit a1baf87

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

cpputil/hstring.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,12 @@ void NetAddr::from_string(const std::string& ipport) {
217217
}
218218

219219
std::string NetAddr::to_string() {
220-
const char* fmt = "%s:%d";
221-
if (ip.find(':') != std::string::npos) {
222-
fmt = "[%s]:%d";
223-
}
224-
return hv::asprintf(fmt, ip.c_str(), port);
220+
return NetAddr::to_string(ip.c_str(), port);
221+
}
222+
223+
std::string NetAddr::to_string(const char* ip, int port) {
224+
const char* fmt = strchr(ip, ':') ? "[%s]:%d" : "%s:%d";
225+
return hv::asprintf(fmt, ip, port);
225226
}
226227

227228
} // end namespace hv

cpputil/hstring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct HV_EXPORT NetAddr {
8585

8686
void from_string(const std::string& ipport);
8787
std::string to_string();
88+
static std::string to_string(const char* ip, int port);
8889
};
8990

9091
} // end namespace hv

cpputil/hurl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class HV_EXPORT HUrl {
3131
namespace hv {
3232

3333
HV_INLINE std::string escapeURL(const std::string& url) {
34-
return HUrl::escape(url, ":/@?=&#+");
34+
return HUrl::escape(url, ":/@[]?=&#+");
3535
}
3636

3737
HV_EXPORT std::string escapeHTML(const std::string& str);

http/HttpMessage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ void HttpRequest::FillHost(const char* host, int port) {
746746
port == DEFAULT_HTTPS_PORT) {
747747
headers["Host"] = host;
748748
} else {
749-
headers["Host"] = asprintf("%s:%d", host, port);
749+
headers["Host"] = hv::NetAddr::to_string(host, port);
750750
}
751751
}
752752
}

0 commit comments

Comments
 (0)