Skip to content

Commit

Permalink
Merge pull request #113 from getsentry/feat/socks5_proxy_support
Browse files Browse the repository at this point in the history
feat: add socks proxy support
  • Loading branch information
JoshuaMoelans authored Nov 21, 2024
2 parents b95f5c6 + 3224a1c commit 852f8fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
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

0 comments on commit 852f8fe

Please sign in to comment.