| ... | @@ -1046,9 +1046,15 @@ pub fn loadDefaultProxies(client: *Client) !void { | ... | @@ -1046,9 +1046,15 @@ pub fn loadDefaultProxies(client: *Client) !void { |
| 1046 | break :http; | 1046 | break :http; |
| 1047 | defer client.allocator.free(content); | 1047 | defer client.allocator.free(content); |
| 1048 | | 1048 | |
| 1049 | const uri = try Uri.parse(content); | 1049 | const uri = Uri.parse(content) catch |
| | 1050 | Uri.parseWithoutScheme(content) catch |
| | 1051 | break :http; |
| | 1052 | |
| | 1053 | const protocol = if (uri.scheme.len == 0) |
| | 1054 | .plain // No scheme, assume http:// |
| | 1055 | else |
| | 1056 | protocol_map.get(uri.scheme) orelse break :http; // Unknown scheme, ignore |
| 1050 | | 1057 | |
| 1051 | const protocol = protocol_map.get(uri.scheme) orelse break :http; // Unknown scheme, ignore | | |
| 1052 | const host = if (uri.host) |host| try client.allocator.dupe(u8, host) else break :http; // Missing host, ignore | 1058 | const host = if (uri.host) |host| try client.allocator.dupe(u8, host) else break :http; // Missing host, ignore |
| 1053 | client.http_proxy = .{ | 1059 | client.http_proxy = .{ |
| 1054 | .allocator = client.allocator, | 1060 | .allocator = client.allocator, |
| ... | @@ -1063,16 +1069,16 @@ pub fn loadDefaultProxies(client: *Client) !void { | ... | @@ -1063,16 +1069,16 @@ pub fn loadDefaultProxies(client: *Client) !void { |
| 1063 | }; | 1069 | }; |
| 1064 | | 1070 | |
| 1065 | if (uri.user != null and uri.password != null) { | 1071 | if (uri.user != null and uri.password != null) { |
| 1066 | const prefix_len = "Basic ".len; | 1072 | const prefix = "Basic "; |
| 1067 | | 1073 | |
| 1068 | const unencoded = try std.fmt.allocPrint(client.allocator, "{s}:{s}", .{ uri.user.?, uri.password.? }); | 1074 | const unencoded = try std.fmt.allocPrint(client.allocator, "{s}:{s}", .{ uri.user.?, uri.password.? }); |
| 1069 | defer client.allocator.free(unencoded); | 1075 | defer client.allocator.free(unencoded); |
| 1070 | | 1076 | |
| 1071 | const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len) + prefix_len); | 1077 | const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len) + prefix.len); |
| 1072 | defer client.allocator.free(buffer); | 1078 | defer client.allocator.free(buffer); |
| 1073 | | 1079 | |
| 1074 | const result = std.base64.standard.Encoder.encode(buffer[prefix_len..], unencoded); | 1080 | const result = std.base64.standard.Encoder.encode(buffer[prefix.len..], unencoded); |
| 1075 | @memcpy(buffer[0..prefix_len], "Basic "); | 1081 | @memcpy(buffer[0..prefix.len], prefix); |
| 1076 | | 1082 | |
| 1077 | try client.http_proxy.?.headers.append("proxy-authorization", result); | 1083 | try client.http_proxy.?.headers.append("proxy-authorization", result); |
| 1078 | } | 1084 | } |
| ... | @@ -1091,11 +1097,17 @@ pub fn loadDefaultProxies(client: *Client) !void { | ... | @@ -1091,11 +1097,17 @@ pub fn loadDefaultProxies(client: *Client) !void { |
| 1091 | break :https; | 1097 | break :https; |
| 1092 | defer client.allocator.free(content); | 1098 | defer client.allocator.free(content); |
| 1093 | | 1099 | |
| 1094 | const uri = try Uri.parse(content); | 1100 | const uri = Uri.parse(content) catch |
| | 1101 | Uri.parseWithoutScheme(content) catch |
| | 1102 | break :https; |
| | 1103 | |
| | 1104 | const protocol = if (uri.scheme.len == 0) |
| | 1105 | .plain // No scheme, assume http:// |
| | 1106 | else |
| | 1107 | protocol_map.get(uri.scheme) orelse break :https; // Unknown scheme, ignore |
| 1095 | | 1108 | |
| 1096 | const protocol = protocol_map.get(uri.scheme) orelse break :https; // Unknown scheme, ignore | | |
| 1097 | const host = if (uri.host) |host| try client.allocator.dupe(u8, host) else break :https; // Missing host, ignore | 1109 | const host = if (uri.host) |host| try client.allocator.dupe(u8, host) else break :https; // Missing host, ignore |
| 1098 | client.http_proxy = .{ | 1110 | client.https_proxy = .{ |
| 1099 | .allocator = client.allocator, | 1111 | .allocator = client.allocator, |
| 1100 | .headers = .{ .allocator = client.allocator }, | 1112 | .headers = .{ .allocator = client.allocator }, |
| 1101 | | 1113 | |
| ... | @@ -1108,16 +1120,16 @@ pub fn loadDefaultProxies(client: *Client) !void { | ... | @@ -1108,16 +1120,16 @@ pub fn loadDefaultProxies(client: *Client) !void { |
| 1108 | }; | 1120 | }; |
| 1109 | | 1121 | |
| 1110 | if (uri.user != null and uri.password != null) { | 1122 | if (uri.user != null and uri.password != null) { |
| 1111 | const prefix_len = "Basic ".len; | 1123 | const prefix = "Basic "; |
| 1112 | | 1124 | |
| 1113 | const unencoded = try std.fmt.allocPrint(client.allocator, "{s}:{s}", .{ uri.user.?, uri.password.? }); | 1125 | const unencoded = try std.fmt.allocPrint(client.allocator, "{s}:{s}", .{ uri.user.?, uri.password.? }); |
| 1114 | defer client.allocator.free(unencoded); | 1126 | defer client.allocator.free(unencoded); |
| 1115 | | 1127 | |
| 1116 | const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len) + prefix_len); | 1128 | const buffer = try client.allocator.alloc(u8, std.base64.standard.Encoder.calcSize(unencoded.len) + prefix.len); |
| 1117 | defer client.allocator.free(buffer); | 1129 | defer client.allocator.free(buffer); |
| 1118 | | 1130 | |
| 1119 | const result = std.base64.standard.Encoder.encode(buffer[prefix_len..], unencoded); | 1131 | const result = std.base64.standard.Encoder.encode(buffer[prefix.len..], unencoded); |
| 1120 | @memcpy(buffer[0..prefix_len], "Basic "); | 1132 | @memcpy(buffer[0..prefix.len], prefix); |
| 1121 | | 1133 | |
| 1122 | try client.https_proxy.?.headers.append("proxy-authorization", result); | 1134 | try client.https_proxy.?.headers.append("proxy-authorization", result); |
| 1123 | } | 1135 | } |