Skip to content

std.http: an explicit port in an https URL is ignored (host becomes 'host:port', port stays 443) #2648

Closed

Description

@ehartford

std.http ignores an explicit port in an https:// URL.

http_parse_url (lib/std/http.w) sets let port: i32 = 443 and takes everything from https:// to the first / as the host. For https://127.0.0.1:8443/x the host is 127.0.0.1:8443 and the port 443; tcp_connect_timeout("127.0.0.1:8443", 443, …) fails and https_get_response returns status -1, so a server on any port but 443 cannot be reached.

Repro:

use std.http
print(https_get_response_timeout("https://example.com:443/", 0, 5000, 5000).status)   // -1; "https://example.com/" works

Expected: host:port splits, as RFC 3986 says ([v6]:port too); the port must be 1..65535, otherwise the URL is refused.

Found writing the #1062 regression test, whose loopback server listens on an ephemeral port.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by e3b0ad0 (PR #2666, stack #2668; battery green on the stack top 9f92dbb). The commit message names the root-cause line and the regression test.

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