mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 23:05:24 +00:00
std.http.Client: ignore unknown proxies, fix basic proxy auth
This commit is contained in:
parent
7dd3099519
commit
dd010e9e90
@ -1028,13 +1028,14 @@ pub fn loadDefaultProxies(client: *Client) !void {
|
||||
|
||||
const uri = try Uri.parse(content);
|
||||
|
||||
const protocol = protocol_map.get(uri.scheme) orelse return error.UnsupportedUrlScheme;
|
||||
const protocol = protocol_map.get(uri.scheme) orelse break :http; // Unknown scheme, ignore
|
||||
const host = if (uri.host) |host| try client.allocator.dupe(u8, host) else break :http; // Missing host, ignore
|
||||
client.http_proxy = .{
|
||||
.allocator = client.allocator,
|
||||
.headers = .{ .allocator = client.allocator },
|
||||
|
||||
.protocol = protocol,
|
||||
.host = if (uri.host) |host| try client.allocator.dupe(u8, host) else return error.UriMissingHost,
|
||||
.host = host,
|
||||
.port = uri.port orelse switch (protocol) {
|
||||
.plain => 80,
|
||||
.tls => 443,
|
||||
@ -1042,13 +1043,16 @@ pub fn loadDefaultProxies(client: *Client) !void {
|
||||
};
|
||||
|
||||
if (uri.user != null and uri.password != null) {
|
||||
const prefix_len = "Basic ".len;
|
||||
|
||||
const unencoded = try std.fmt.allocPrint(client.allocator, "{s}:{s}", .{ uri.user.?, uri.password.? });
|
||||
defer client.allocator.free(unencoded);
|
||||
|
||||
const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len));
|
||||
const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len) + prefix_len);
|
||||
defer client.allocator.free(buffer);
|
||||
|
||||
const result = std.base64.standard.Encoder.encode(buffer, unencoded);
|
||||
const result = std.base64.standard.Encoder.encode(buffer[prefix_len..], unencoded);
|
||||
@memcpy(buffer[0..prefix_len], "Basic ");
|
||||
|
||||
try client.http_proxy.?.headers.append("proxy-authorization", result);
|
||||
}
|
||||
@ -1069,13 +1073,14 @@ pub fn loadDefaultProxies(client: *Client) !void {
|
||||
|
||||
const uri = try Uri.parse(content);
|
||||
|
||||
const protocol = protocol_map.get(uri.scheme) orelse return error.UnsupportedUrlScheme;
|
||||
const protocol = protocol_map.get(uri.scheme) orelse break :https; // Unknown scheme, ignore
|
||||
const host = if (uri.host) |host| try client.allocator.dupe(u8, host) else break :https; // Missing host, ignore
|
||||
client.http_proxy = .{
|
||||
.allocator = client.allocator,
|
||||
.headers = .{ .allocator = client.allocator },
|
||||
|
||||
.protocol = protocol,
|
||||
.host = if (uri.host) |host| try client.allocator.dupe(u8, host) else return error.UriMissingHost,
|
||||
.host = host,
|
||||
.port = uri.port orelse switch (protocol) {
|
||||
.plain => 80,
|
||||
.tls => 443,
|
||||
@ -1083,13 +1088,16 @@ pub fn loadDefaultProxies(client: *Client) !void {
|
||||
};
|
||||
|
||||
if (uri.user != null and uri.password != null) {
|
||||
const prefix_len = "Basic ".len;
|
||||
|
||||
const unencoded = try std.fmt.allocPrint(client.allocator, "{s}:{s}", .{ uri.user.?, uri.password.? });
|
||||
defer client.allocator.free(unencoded);
|
||||
|
||||
const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len));
|
||||
const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len) + prefix_len);
|
||||
defer client.allocator.free(buffer);
|
||||
|
||||
const result = std.base64.standard.Encoder.encode(buffer, unencoded);
|
||||
const result = std.base64.standard.Encoder.encode(buffer[prefix_len..], unencoded);
|
||||
@memcpy(buffer[0..prefix_len], "Basic ");
|
||||
|
||||
try client.https_proxy.?.headers.append("proxy-authorization", result);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user