diff --git a/util/net/http_transport_mac.mm b/util/net/http_transport_mac.mm index dd28e0242..bfd844b19 100644 --- a/util/net/http_transport_mac.mm +++ b/util/net/http_transport_mac.mm @@ -282,14 +282,26 @@ static bool ExecuteProxyRequest(NSMutableURLRequest* request, NSString* hostNS = base::SysUTF8ToNSString(host); NSNumber* proxy_port = @(std::stoi(port)); - NSDictionary* proxyDict = @{ - (__bridge id)kCFNetworkProxiesHTTPEnable : @YES, - (__bridge id)kCFNetworkProxiesHTTPPort : proxy_port, - (__bridge id)kCFNetworkProxiesHTTPProxy : hostNS, - @"HTTPSEnable" : @YES, - @"HTTPSPort" : proxy_port, - @"HTTPSProxy" : hostNS, - }; + NSDictionary* proxyDict; + + if ([schemeNS isEqualToString:@"http"] || [schemeNS isEqualToString:@"https"]) { + // The keys in this dictionary refer to the target URL, + // whereas `schemeNS` refers to the proxy URL. + proxyDict = @{ + @"HTTPEnable" : @YES, + @"HTTPPort" : proxy_port, + @"HTTPProxy" : hostNS, + @"HTTPSEnable" : @YES, + @"HTTPSPort" : proxy_port, + @"HTTPSProxy" : hostNS + }; + } else if ([schemeNS isEqualToString:@"socks5"]) { + proxyDict = @{ + @"SOCKSEnable" : @YES, + @"SOCKSPort" : proxy_port, + @"SOCKSProxy" : hostNS + }; + } sessionConfig.connectionProxyDictionary = proxyDict; NSURLSession* session = [NSURLSession sessionWithConfiguration:sessionConfig]; diff --git a/util/net/url.cc b/util/net/url.cc index 9d037bdcd..0e819fae9 100644 --- a/util/net/url.cc +++ b/util/net/url.cc @@ -53,6 +53,7 @@ bool CrackURL(const std::string& url, size_t host_start; static constexpr const char kHttp[] = "http://"; static constexpr const char kHttps[] = "https://"; + static constexpr const char kSocks[] = "socks5://"; if (url.compare(0, strlen(kHttp), kHttp) == 0) { result_scheme = "http"; result_port = "80"; @@ -61,8 +62,12 @@ bool CrackURL(const std::string& url, result_scheme = "https"; result_port = "443"; host_start = strlen(kHttps); + } else if (url.compare(0, strlen(kSocks), kSocks) == 0) { + result_scheme = "socks5"; + result_port = "1080"; + host_start = strlen(kSocks); } else { - LOG(ERROR) << "expecting http or https"; + LOG(ERROR) << "expecting http, https or socks5"; return false; }