From bb72651cefc37dcc2c89f0c9deefd10e07fc98e6 Mon Sep 17 00:00:00 2001 From: Ben Copsey Date: Thu, 25 Jun 2009 11:59:08 +0100 Subject: [PATCH] Added auto-detect for proxies - please let me know if you find problems! Tweaks to text in iPhone sample app --- Classes/ASIHTTPRequest.m | 11 +++++ Classes/Tests/ASIHTTPRequestTests.m | 1 - Classes/Tests/ASINetworkQueueTests.m | 1 + Mac.xcodeproj/project.pbxproj | 6 +++ iPhone Sample/XIBs/Queue.xib | 62 ++++++++++++++++++++++----- iPhone Sample/XIBs/UploadProgress.xib | 9 ++-- 6 files changed, 74 insertions(+), 16 deletions(-) diff --git a/Classes/ASIHTTPRequest.m b/Classes/ASIHTTPRequest.m index ac870110..dc083e13 100644 --- a/Classes/ASIHTTPRequest.m +++ b/Classes/ASIHTTPRequest.m @@ -12,6 +12,9 @@ #import "ASIHTTPRequest.h" #import +#ifndef TARGET_OS_IPHONE +#import +#endif // We use our own custom run loop mode as CoreAnimation seems to want to hijack our threads otherwise static CFStringRef ASIHTTPRequestRunMode = CFSTR("ASIHTTPRequest"); @@ -442,6 +445,14 @@ - (void)startRequest CFReadStreamSetProperty(readStream, kCFStreamPropertySSLSettings, [NSMutableDictionary dictionaryWithObject:(NSString *)kCFBooleanFalse forKey:(NSString *)kCFStreamSSLValidatesCertificateChain]); } + // Detect proxy settings and apply them +#if TARGET_OS_IPHONE + NSDictionary *proxySettings = [(NSDictionary *)CFNetworkCopySystemProxySettings() autorelease]; +#else + NSDictionary *proxySettings = [(NSDictionary *)SCDynamicStoreCopyProxies(NULL) autorelease]; +#endif + CFReadStreamSetProperty(readStream, kCFStreamPropertyHTTPProxy, proxySettings); + // Set the client CFStreamClientContext ctxt = {0, self, NULL, NULL, NULL}; if (!CFReadStreamSetClient(readStream, kNetworkEvents, ReadStreamClientCallBack, &ctxt)) { diff --git a/Classes/Tests/ASIHTTPRequestTests.m b/Classes/Tests/ASIHTTPRequestTests.m index d0af5820..dcd6f324 100644 --- a/Classes/Tests/ASIHTTPRequestTests.m +++ b/Classes/Tests/ASIHTTPRequestTests.m @@ -334,7 +334,6 @@ - (void)testCookies if (!foundCookie) { return; } - // Test a cookie is presented when manually added to the request url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/read_cookie"] autorelease]; request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; diff --git a/Classes/Tests/ASINetworkQueueTests.m b/Classes/Tests/ASINetworkQueueTests.m index 4dc699fc..60e69e6d 100755 --- a/Classes/Tests/ASINetworkQueueTests.m +++ b/Classes/Tests/ASINetworkQueueTests.m @@ -361,6 +361,7 @@ - (void)testWithNoListener [networkQueue go]; [networkQueue waitUntilAllOperationsAreFinished]; + // This test may fail if you are using a proxy and it returns a page when you try to connect to a bad port. GHAssertTrue(!request_succeeded && request_didfail,@"Request to resource without listener succeeded but should have failed"); [networkQueue release]; diff --git a/Mac.xcodeproj/project.pbxproj b/Mac.xcodeproj/project.pbxproj index 57bff581..3466fe88 100644 --- a/Mac.xcodeproj/project.pbxproj +++ b/Mac.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; + B53FADE80FF38B2A002E2DE6 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B53FADE70FF38B2A002E2DE6 /* SystemConfiguration.framework */; }; + B53FADF90FF38BA9002E2DE6 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B53FADE70FF38B2A002E2DE6 /* SystemConfiguration.framework */; }; B55B5D200F76568E0064029C /* ASIFormDataRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = B55B5D120F76568E0064029C /* ASIFormDataRequest.m */; }; B55B5D210F76568E0064029C /* ASIHTTPRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = B55B5D140F76568E0064029C /* ASIHTTPRequest.m */; }; B55B5D220F76568E0064029C /* ASINetworkQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = B55B5D160F76568E0064029C /* ASINetworkQueue.m */; }; @@ -48,6 +50,7 @@ 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 8D1107320486CEB800E47090 /* Mac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mac.app; sourceTree = BUILT_PRODUCTS_DIR; }; + B53FADE70FF38B2A002E2DE6 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; B55B5D110F76568E0064029C /* ASIFormDataRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIFormDataRequest.h; sourceTree = ""; }; B55B5D120F76568E0064029C /* ASIFormDataRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIFormDataRequest.m; sourceTree = ""; }; B55B5D130F76568E0064029C /* ASIHTTPRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIHTTPRequest.h; sourceTree = ""; }; @@ -83,6 +86,7 @@ files = ( 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, B55B5EB80F7658200064029C /* libz.1.2.3.dylib in Frameworks */, + B53FADF90FF38BA9002E2DE6 /* SystemConfiguration.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -92,6 +96,7 @@ files = ( B55B60140F7659A30064029C /* libz.1.2.3.dylib in Frameworks */, B5B513680FBEE435002C74D0 /* GHUnit.framework in Frameworks */, + B53FADE80FF38B2A002E2DE6 /* SystemConfiguration.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -135,6 +140,7 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */, 19C28FACFE9D520D11CA2CBB /* Products */, B55B5EB70F7658200064029C /* libz.1.2.3.dylib */, + B53FADE70FF38B2A002E2DE6 /* SystemConfiguration.framework */, ); name = Mac; sourceTree = ""; diff --git a/iPhone Sample/XIBs/Queue.xib b/iPhone Sample/XIBs/Queue.xib index 14fe95eb..ba906d38 100644 --- a/iPhone Sample/XIBs/Queue.xib +++ b/iPhone Sample/XIBs/Queue.xib @@ -2,9 +2,9 @@ 528 - 9G55 + 9J61 677 - 949.43 + 949.46 353.00 YES @@ -59,6 +59,26 @@ 1.000000e+01 0 + + + 292 + {{163, 272}, {143, 87}} + + NO + YES + NO + See the Mac sample app for a slightly more sophisticated example, with an addtional progress indicator for each request + + Helvetica + 1.200000e+01 + 16 + + + + 1 + 1.000000e+01 + 0 + 292 @@ -86,11 +106,15 @@ 1 MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA + + 3 + MAA + 292 - {{20, 184}, {135, 87}} + {{20, 177}, {135, 87}} NO NO @@ -100,7 +124,7 @@ 292 - {{20, 279}, {135, 87}} + {{20, 272}, {135, 87}} NO NO @@ -110,7 +134,7 @@ 292 - {{163, 184}, {137, 87}} + {{163, 177}, {137, 87}} NO NO @@ -120,7 +144,7 @@ 292 - {{20, 379}, {280, 9}} + {{20, 367}, {280, 9}} NO YES @@ -241,14 +265,15 @@ YES - - + + + @@ -303,6 +328,11 @@ + + 24 + + + @@ -319,6 +349,7 @@ 14.IBPluginDependency 21.IBPluginDependency 22.IBPluginDependency + 24.IBPluginDependency 8.IBPluginDependency 9.IBPluginDependency @@ -336,6 +367,7 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -358,11 +390,18 @@ - 23 + 24 YES + + NSObject + + IBProjectSource + Frameworks/libGHUnitIPhone/GHUNSObject+Swizzle.h + + QueueViewController UIViewController @@ -391,13 +430,14 @@ IBProjectSource - QueueViewController.h + iPhone Sample/QueueViewController.h 0 - ../asi-http-request.xcodeproj + ../../iPhone.xcodeproj 3 + 3.0 diff --git a/iPhone Sample/XIBs/UploadProgress.xib b/iPhone Sample/XIBs/UploadProgress.xib index 859cf6c5..78602d34 100644 --- a/iPhone Sample/XIBs/UploadProgress.xib +++ b/iPhone Sample/XIBs/UploadProgress.xib @@ -39,14 +39,15 @@ 292 - {{20, 20}, {280, 127}} + {{20, 20}, {280, 144}} NO YES NO RGVtb25zdHJhdGVzIFBPU1RpbmcgY29udGVudCB0byBhIFVSTCwgc2hvd2luZyB1cGxvYWQgcHJvZ3Jl c3MuCgpZb3UnbGwgb25seSBzZWUgYWNjdXJhdGUgcHJvZ3Jlc3MgZm9yIHVwbG9hZHMgd2hlbiB0aGUg -cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCIChpbiAyLjIuMSBTREspA +cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCIChpbiAyLjIuMSBTREspLCBvciB3aGVuIHRo +ZSByZXF1ZXN0IGJvZHkgaXMgbGFyZ2VyIHRoYW4gMzJLQiAoaW4gMy4wIFNESyk Helvetica 1.400000e+01 @@ -65,7 +66,7 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCIChpbiAyLjIuMSBTREspA 292 - {{20, 161}, {72, 37}} + {{20, 186}, {72, 37}} NO NO @@ -97,7 +98,7 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCIChpbiAyLjIuMSBTREspA 292 - {{20, 215}, {280, 9}} + {{20, 240}, {280, 9}} NO YES