Ben Copsey

Hopefully make SOCKS proxies work

@@ -333,6 +333,10 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -333,6 +333,10 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
333 NSString *proxyHost; 333 NSString *proxyHost;
334 int proxyPort; 334 int proxyPort;
335 335
  336 + // ASIHTTPRequest will assume kCFProxyTypeHTTP if the proxy type could not be automatically determined
  337 + // Set to kCFProxyTypeSOCKS if you are manually configuring a SOCKS proxy
  338 + NSString *proxyType;
  339 +
336 // URL for a PAC (Proxy Auto Configuration) file. If you want to set this yourself, it's probably best if you use a local file 340 // URL for a PAC (Proxy Auto Configuration) file. If you want to set this yourself, it's probably best if you use a local file
337 NSURL *PACurl; 341 NSURL *PACurl;
338 342
@@ -749,6 +753,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; @@ -749,6 +753,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
749 753
750 @property (retain) NSString *proxyHost; 754 @property (retain) NSString *proxyHost;
751 @property (assign) int proxyPort; 755 @property (assign) int proxyPort;
  756 +@property (retain) NSString *proxyType;
752 757
753 @property (retain,setter=setURL:) NSURL *url; 758 @property (retain,setter=setURL:) NSURL *url;
754 @property (retain) NSURL *originalURL; 759 @property (retain) NSURL *originalURL;
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 24
25 // Automatically set on build 25 // Automatically set on build
26 26
27 -NSString *ASIHTTPRequestVersion = @"v1.7-4 2010-06-30"; 27 +NSString *ASIHTTPRequestVersion = @"v1.7-5 2010-06-30";
28 28
29 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; 29 NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
30 30
@@ -936,17 +936,35 @@ static NSOperationQueue *sharedQueue = nil; @@ -936,17 +936,35 @@ static NSOperationQueue *sharedQueue = nil;
936 NSDictionary *settings = [proxies objectAtIndex:0]; 936 NSDictionary *settings = [proxies objectAtIndex:0];
937 [self setProxyHost:[settings objectForKey:(NSString *)kCFProxyHostNameKey]]; 937 [self setProxyHost:[settings objectForKey:(NSString *)kCFProxyHostNameKey]];
938 [self setProxyPort:[[settings objectForKey:(NSString *)kCFProxyPortNumberKey] intValue]]; 938 [self setProxyPort:[[settings objectForKey:(NSString *)kCFProxyPortNumberKey] intValue]];
  939 + [self setProxyType:[settings objectForKey:(NSString *)kCFProxyTypeKey]];
939 } 940 }
940 } 941 }
941 if ([self proxyHost] && [self proxyPort]) { 942 if ([self proxyHost] && [self proxyPort]) {
942 - NSString *hostKey = (NSString *)kCFStreamPropertyHTTPProxyHost; 943 + NSString *hostKey;
943 - NSString *portKey = (NSString *)kCFStreamPropertyHTTPProxyPort; 944 + NSString *portKey;
944 - if ([[[[self url] scheme] lowercaseString] isEqualToString:@"https"]) { 945 +
945 - hostKey = (NSString *)kCFStreamPropertyHTTPSProxyHost; 946 + if (![self proxyType]) {
946 - portKey = (NSString *)kCFStreamPropertyHTTPSProxyPort; 947 + [self setProxyType:(NSString *)kCFProxyTypeHTTP];
  948 + }
  949 +
  950 + if ([[self proxyType] isEqualToString:(NSString *)kCFProxyTypeSOCKS]) {
  951 + hostKey = (NSString *)kCFStreamPropertySOCKSProxyHost;
  952 + portKey = (NSString *)kCFStreamPropertySOCKSProxyPort;
  953 + } else {
  954 + hostKey = (NSString *)kCFStreamPropertyHTTPProxyHost;
  955 + portKey = (NSString *)kCFStreamPropertyHTTPProxyPort;
  956 + if ([[[[self url] scheme] lowercaseString] isEqualToString:@"https"]) {
  957 + hostKey = (NSString *)kCFStreamPropertyHTTPSProxyHost;
  958 + portKey = (NSString *)kCFStreamPropertyHTTPSProxyPort;
  959 + }
947 } 960 }
948 NSMutableDictionary *proxyToUse = [NSMutableDictionary dictionaryWithObjectsAndKeys:[self proxyHost],hostKey,[NSNumber numberWithInt:[self proxyPort]],portKey,nil]; 961 NSMutableDictionary *proxyToUse = [NSMutableDictionary dictionaryWithObjectsAndKeys:[self proxyHost],hostKey,[NSNumber numberWithInt:[self proxyPort]],portKey,nil];
949 - CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPProxy, proxyToUse); 962 +
  963 + if ([[self proxyType] isEqualToString:(NSString *)kCFProxyTypeSOCKS]) {
  964 + CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertySOCKSProxy, proxyToUse);
  965 + } else {
  966 + CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertyHTTPProxy, proxyToUse);
  967 + }
950 } 968 }
951 969
952 // 970 //
@@ -3996,6 +4014,7 @@ static NSOperationQueue *sharedQueue = nil; @@ -3996,6 +4014,7 @@ static NSOperationQueue *sharedQueue = nil;
3996 @synthesize proxyCredentials; 4014 @synthesize proxyCredentials;
3997 @synthesize proxyHost; 4015 @synthesize proxyHost;
3998 @synthesize proxyPort; 4016 @synthesize proxyPort;
  4017 +@synthesize proxyType;
3999 @synthesize PACurl; 4018 @synthesize PACurl;
4000 @synthesize authenticationScheme; 4019 @synthesize authenticationScheme;
4001 @synthesize proxyAuthenticationScheme; 4020 @synthesize proxyAuthenticationScheme;