authorgravatar for truemedian@gmail.comNameless <truemedian@gmail.com> 2023-10-18 11:03:27-05:00
committergravatar for truemedian@gmail.comNameless <truemedian@gmail.com> 2023-10-21 20:53:00-05:00
logdd010e9e90c5ff6cbd5f390dbbb534ddf2fc87b6
treef256dd8494f678118eb208e1602a311d47020b7f
parent7dd3099519fd0f64fcdf11791fc9ba95a68e0637
signature Commit is signed but in an unrecognized format.

std.http.Client: ignore unknown proxies, fix basic proxy auth


1 files changed, 16 insertions(+), 8 deletions(-)

lib/std/http/Client.zig+16-8
......@@ -1028,13 +1028,14 @@ pub fn loadDefaultProxies(client: *Client) !void {
10281028
10291029 const uri = try Uri.parse(content);
10301030
1031 const protocol = protocol_map.get(uri.scheme) orelse return error.UnsupportedUrlScheme;
1031 const protocol = protocol_map.get(uri.scheme) orelse break :http; // Unknown scheme, ignore
1032 const host = if (uri.host) |host| try client.allocator.dupe(u8, host) else break :http; // Missing host, ignore
10321033 client.http_proxy = .{
10331034 .allocator = client.allocator,
10341035 .headers = .{ .allocator = client.allocator },
10351036
10361037 .protocol = protocol,
1037 .host = if (uri.host) |host| try client.allocator.dupe(u8, host) else return error.UriMissingHost,
1038 .host = host,
10381039 .port = uri.port orelse switch (protocol) {
10391040 .plain => 80,
10401041 .tls => 443,
......@@ -1042,13 +1043,16 @@ pub fn loadDefaultProxies(client: *Client) !void {
10421043 };
10431044
10441045 if (uri.user != null and uri.password != null) {
1046 const prefix_len = "Basic ".len;
1047
10451048 const unencoded = try std.fmt.allocPrint(client.allocator, "{s}:{s}", .{ uri.user.?, uri.password.? });
10461049 defer client.allocator.free(unencoded);
10471050
1048 const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len));
1051 const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len) + prefix_len);
10491052 defer client.allocator.free(buffer);
10501053
1051 const result = std.base64.standard.Encoder.encode(buffer, unencoded);
1054 const result = std.base64.standard.Encoder.encode(buffer[prefix_len..], unencoded);
1055 @memcpy(buffer[0..prefix_len], "Basic ");
10521056
10531057 try client.http_proxy.?.headers.append("proxy-authorization", result);
10541058 }
......@@ -1069,13 +1073,14 @@ pub fn loadDefaultProxies(client: *Client) !void {
10691073
10701074 const uri = try Uri.parse(content);
10711075
1072 const protocol = protocol_map.get(uri.scheme) orelse return error.UnsupportedUrlScheme;
1076 const protocol = protocol_map.get(uri.scheme) orelse break :https; // Unknown scheme, ignore
1077 const host = if (uri.host) |host| try client.allocator.dupe(u8, host) else break :https; // Missing host, ignore
10731078 client.http_proxy = .{
10741079 .allocator = client.allocator,
10751080 .headers = .{ .allocator = client.allocator },
10761081
10771082 .protocol = protocol,
1078 .host = if (uri.host) |host| try client.allocator.dupe(u8, host) else return error.UriMissingHost,
1083 .host = host,
10791084 .port = uri.port orelse switch (protocol) {
10801085 .plain => 80,
10811086 .tls => 443,
......@@ -1083,13 +1088,16 @@ pub fn loadDefaultProxies(client: *Client) !void {
10831088 };
10841089
10851090 if (uri.user != null and uri.password != null) {
1091 const prefix_len = "Basic ".len;
1092
10861093 const unencoded = try std.fmt.allocPrint(client.allocator, "{s}:{s}", .{ uri.user.?, uri.password.? });
10871094 defer client.allocator.free(unencoded);
10881095
1089 const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len));
1096 const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len) + prefix_len);
10901097 defer client.allocator.free(buffer);
10911098
1092 const result = std.base64.standard.Encoder.encode(buffer, unencoded);
1099 const result = std.base64.standard.Encoder.encode(buffer[prefix_len..], unencoded);
1100 @memcpy(buffer[0..prefix_len], "Basic ");
10931101
10941102 try client.https_proxy.?.headers.append("proxy-authorization", result);
10951103 }