GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — WebSocket handshake Host header always includes default port (RFC 7230 §5.4) · Issue #2480 · yhirose/cpp-httplib

WebSocket handshake Host header always includes default port (RFC 7230 §5.4) #2480

New issue
Copy link
New issue
Copy link
Closed
Closed
WebSocket handshake Host header always includes default port (RFC 7230 §5.4)#2480
Copy link

Description

@uriba107
uriba107
opened on Jun 26, 2026
Issue body actions

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).

Activity

  1. yhirose
    closed this as completedin 45da614on Jul 2, 2026
  2. yhirose commented on Jul 2, 2026

    @yhirose
    yhirose
    on Jul 2, 2026
    Owner
    More actions

    @uriba107 thanks for the report!

  3. SiarheiHerasiuta
    added a commit that references this issue on Jul 2, 2026

    Omit default port from WebSocket handshake Host header (Fix yhirose#2480

    This issue will close once commit 45da614 is merged into the 'master' branch.
    45da614
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.