diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-04-13 03:39:35 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-13 03:39:35 -0700 |
| commit | 54d1a529f652cf79bf9edc95463380c5c853e4db (patch) | |
| tree | 6e8c0f3a60a2468dd31184108a25dbc8ba3b741c /lib/std/http/Client.zig | |
| parent | 7cc0e6d4cd5d699d5377cf47ee27a2e089d046bf (diff) | |
| parent | 0a3dff8125662feee7e348ed01478482ded0aa27 (diff) | |
| download | zig-54d1a529f652cf79bf9edc95463380c5c853e4db.tar.gz zig-54d1a529f652cf79bf9edc95463380c5c853e4db.zip | |
Merge pull request #19637 from ziglang/http-host-port
std.http.Client: omit port in http host header sometimes
Diffstat (limited to 'lib/std/http/Client.zig')
| -rw-r--r-- | lib/std/http/Client.zig | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig index 20d9956cef..837bdc63c7 100644 --- a/lib/std/http/Client.zig +++ b/lib/std/http/Client.zig @@ -805,7 +805,7 @@ pub const Request = struct { } req.uri = valid_uri; - req.connection = try req.client.connect(new_host, valid_uri.port.?, protocol); + req.connection = try req.client.connect(new_host, uriPort(valid_uri, protocol), protocol); req.redirect_behavior.subtractOne(); req.response.parser.reset(); @@ -1264,7 +1264,7 @@ fn createProxyFromEnvVar(arena: Allocator, env_var_names: []const []const u8) !? .protocol = protocol, .host = valid_uri.host.?.raw, .authorization = authorization, - .port = valid_uri.port.?, + .port = uriPort(valid_uri, protocol), .supports_connect = true, }; return proxy; @@ -1582,11 +1582,14 @@ fn validateUri(uri: Uri, arena: Allocator) !struct { Connection.Protocol, Uri } valid_uri.host = .{ .raw = try (uri.host orelse return error.UriMissingHost).toRawMaybeAlloc(arena), }; - valid_uri.port = uri.port orelse switch (protocol) { + return .{ protocol, valid_uri }; +} + +fn uriPort(uri: Uri, protocol: Connection.Protocol) u16 { + return uri.port orelse switch (protocol) { .plain => 80, .tls => 443, }; - return .{ protocol, valid_uri }; } /// Open a connection to the host specified by `uri` and prepare to send a HTTP request. @@ -1634,7 +1637,7 @@ pub fn open( } const conn = options.connection orelse - try client.connect(valid_uri.host.?.raw, valid_uri.port.?, protocol); + try client.connect(valid_uri.host.?.raw, uriPort(valid_uri, protocol), protocol); var req: Request = .{ .uri = valid_uri, |
