Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 14, 2025

cpp-httplib was sending Host: hostname:443 for HTTPS on port 443, causing failures with RFC-strict servers like roblox.com. curl and browsers omit default ports per RFC 7230 §5.4.

Current Implementation

The fix is already present in v0.28.0. make_host_and_port_string() (httplib.h:7775-7776) correctly omits:

  • Port 80 for HTTP (is_ssl=false)
  • Port 443 for HTTPS (is_ssl=true)
// Append port if not default
if ((!is_ssl && port == 80) || (is_ssl && port == 443)) {
    ; // do nothing
} else {
    result += ":" + std::to_string(port);
}

Verification

  • Unit tests cover IPv4/IPv6, default/non-default ports, edge cases (test/test.cc:10880-10975)
  • Manual verification confirms roblox.com:443Host: roblox.com
  • Behavior matches curl, browsers, RFC 7230

No code changes required. Implementation is correct and production-ready.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https *.1 *.srl httplib.h httplib.cc _build* *.dSYM (dns block)
  • google.com
    • Triggering command: ./test ./test --gtest_filter=*Host* -disable-llvm-verifier -discard-value-names -main-file-name test_host_e2e.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all (dns block)
  • www.httpwatch.com
    • Triggering command: ./test ./test --gtest_filter=*Host* -disable-llvm-verifier -discard-value-names -main-file-name test_host_e2e.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Summary

Fixes an interoperability issue where cpp-httplib sends a Host: hostname:443 header for HTTPS requests on the default port (443), causing some servers (such as roblox.com) to return errors (e.g., 404 "No Service Found"), while tools like curl and browsers work as expected.

Background

  • In cpp-httplib v0.27.0, as part of consistency changes, the Host header always includes the port, even for default ports 80 (HTTP) and 443 (HTTPS), so Host: roblox.com:443 gets sent.
  • The HTTP RFC and standard tools (curl, browsers) omit the port in the Host header when it is the default.
  • Some production servers strictly require this and reject Host: roblox.com:443 on port 443.
  • curl does not send the port for default ports, and works fine with the same server.

Solution

  • This patch modifies make_host_and_port_string so that for HTTPS (SSL) on port 443 and HTTP on port 80, the Host header omits the port number, matching curl, browsers, and the RFC.
  • All other (non-default) ports are still handled as before.
  • Unit tests will be added/expanded to verify this behavior.

Impact

  • Fixes real-world compatibility with strict servers (roblox.com, etc).
  • Preserves improvements for IPv6, UNIX sockets, and non-default ports from v0.27.0.

References

This pull request was created as a result of the following prompt from Copilot chat.

Summary

Fixes an interoperability issue where cpp-httplib sends a Host: hostname:443 header for HTTPS requests on the default port (443), causing some servers (such as roblox.com) to return errors (e.g., 404 "No Service Found"), while tools like curl and browsers work as expected.

Background

  • In cpp-httplib v0.27.0, as part of consistency changes, the Host header always includes the port, even for default ports 80 (HTTP) and 443 (HTTPS), so Host: roblox.com:443 gets sent.
  • The HTTP RFC and standard tools (curl, browsers) omit the port in the Host header when it is the default.
  • Some production servers strictly require this and reject Host: roblox.com:443 on port 443.
  • curl does not send the port for default ports, and works fine with the same server.

Solution

  • This patch modifies make_host_and_port_string so that for HTTPS (SSL) on port 443 and HTTP on port 80, the Host header omits the port number, matching curl, browsers, and the RFC.
  • All other (non-default) ports are still handled as before.
  • Unit tests will be added/expanded to verify this behavior.

Impact

  • Fixes real-world compatibility with strict servers (roblox.com, etc).
  • Preserves improvements for IPv6, UNIX sockets, and non-default ports from v0.27.0.

References


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix Host header for HTTPS requests on default port Verify Host header omits default ports per RFC 7230 Dec 14, 2025
Copilot AI requested a review from yhirose December 14, 2025 12:40
@yhirose yhirose marked this pull request as ready for review December 14, 2025 13:16
@yhirose yhirose merged commit 63b07ad into master Dec 14, 2025
9 checks passed
@yhirose yhirose deleted the copilot/fix-host-header-issue branch December 28, 2025 19:51
noresources pushed a commit to noresources/cpp-httplib that referenced this pull request Dec 31, 2025
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
noresources pushed a commit to noresources/cpp-httplib that referenced this pull request Dec 31, 2025
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
noresources pushed a commit to noresources/cpp-httplib that referenced this pull request Dec 31, 2025
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
noresources pushed a commit to noresources/cpp-httplib that referenced this pull request Dec 31, 2025
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
noresources pushed a commit to depinxi/cpp-httplib that referenced this pull request Jan 6, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants