Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add socks proxy support #113

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions util/net/http_transport_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
7 changes: 6 additions & 1 deletion util/net/url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
}

Expand Down