Skip to content

Commit

Permalink
fix: FillHost adapt ipv6 (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
ithewei committed Feb 26, 2025
1 parent 9a3c19c commit a1baf87
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions cpputil/hstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@ void NetAddr::from_string(const std::string& ipport) {
}

std::string NetAddr::to_string() {
const char* fmt = "%s:%d";
if (ip.find(':') != std::string::npos) {
fmt = "[%s]:%d";
}
return hv::asprintf(fmt, ip.c_str(), port);
return NetAddr::to_string(ip.c_str(), port);
}

std::string NetAddr::to_string(const char* ip, int port) {
const char* fmt = strchr(ip, ':') ? "[%s]:%d" : "%s:%d";
return hv::asprintf(fmt, ip, port);
}

} // end namespace hv
1 change: 1 addition & 0 deletions cpputil/hstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct HV_EXPORT NetAddr {

void from_string(const std::string& ipport);
std::string to_string();
static std::string to_string(const char* ip, int port);
};

} // end namespace hv
Expand Down
2 changes: 1 addition & 1 deletion cpputil/hurl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HV_EXPORT HUrl {
namespace hv {

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

HV_EXPORT std::string escapeHTML(const std::string& str);
Expand Down
2 changes: 1 addition & 1 deletion http/HttpMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ void HttpRequest::FillHost(const char* host, int port) {
port == DEFAULT_HTTPS_PORT) {
headers["Host"] = host;
} else {
headers["Host"] = asprintf("%s:%d", host, port);
headers["Host"] = hv::NetAddr::to_string(host, port);
}
}
}
Expand Down

0 comments on commit a1baf87

Please sign in to comment.