perform_websocket_handshake always includes :port in Host header even for default ports
httplib version: 0.48.0
In perform_websocket_handshake (httplib.h:8872), the Host header is always sent as host:port:
req_str += "Host: " + host + ":" + std::to_string(port) + "\r\n";
This sends Host: example.com:443 or Host: example.com:80 when those are the default ports for the scheme, violating RFC 7230 §5.4 (https://www.rfc-editor.org/rfc/rfc7230#section-5.4) which states clients SHOULD omit the port when it matches the default.
The library already has a correct helper at httplib.h:10645 that handles this:
inline std::string make_host_and_port_string(const std::string &host, int port, bool is_ssl) {
auto result = prepare_host_string(host);
if ((!is_ssl && port == 80) || (is_ssl && port == 443)) {
; // do nothing
} else {
result += ":" + std::to_string(port);
}
return result;
}
perform_websocket_handshake should use make_host_and_port_string(host, port, is_ssl) instead of the unconditional host + ":" + port string, but it doesn't have access to the SSL flag (the handshake function receives a generic Stream&).
Practical impact: Some CDNs (notably Microsoft CDN for Edge TTS) may route requests differently when the :443 suffix is present on the Host header, causing WebSocket upgrades to succeed but produce silent failures (no data frames delivered).
Suggested fix: Either thread the is_ssl flag through to perform_websocket_handshake, or check port == 80 || port == 443 directly (the scheme is already known by the caller — the client knows whether it connected over SSL).