Permalink
Browse files

initial commit of updated asinetwork framework

  • Loading branch information...
2 parents 4c42c90 + 57f7ff2 commit 678121f7263232bea01026cd089784e571c95d64 @pellet committed Jul 11, 2011
Showing with 7,591 additions and 2,037 deletions.
  1. +1 −0 .gitignore
  2. +14 −0 Build Scripts/fetch_ios_ghunit.rb
  3. +14 −0 Build Scripts/fetch_mac_ghunit.rb
  4. +2 −2 { → Build Scripts}/set_version_number.rb
  5. +14 −10 Classes/ASIAuthenticationDialog.m
  6. +61 −14 Classes/ASICacheDelegate.h
  7. +42 −0 Classes/ASIDataCompressor.h
  8. +219 −0 Classes/ASIDataCompressor.m
  9. +41 −0 Classes/ASIDataDecompressor.h
  10. +218 −0 Classes/ASIDataDecompressor.m
  11. +2 −7 Classes/ASIDownloadCache.h
  12. +258 −160 Classes/ASIDownloadCache.m
  13. +2 −2 Classes/ASIFormDataRequest.h
  14. +36 −30 Classes/ASIFormDataRequest.m
  15. +191 −50 Classes/ASIHTTPRequest.h
  16. +1,796 −988 Classes/ASIHTTPRequest.m
  17. +5 −0 Classes/ASIHTTPRequestConfig.h
  18. +3 −1 Classes/ASIHTTPRequestDelegate.h
  19. +11 −11 Classes/ASIInputStream.m
  20. +7 −1 Classes/ASINetworkQueue.h
  21. +27 −6 Classes/ASINetworkQueue.m
  22. +80 −0 Classes/ASIWebPageRequest/ASIWebPageRequest.h
  23. +703 −0 Classes/ASIWebPageRequest/ASIWebPageRequest.m
  24. +1 −1 Classes/S3/ASINSXMLParserCompat.h
  25. +3 −3 Classes/S3/ASIS3Bucket.m
  26. +2 −2 Classes/S3/ASIS3BucketObject.m
  27. +6 −9 Classes/S3/ASIS3BucketRequest.h
  28. +23 −26 Classes/S3/ASIS3BucketRequest.m
  29. +16 −6 Classes/S3/ASIS3ObjectRequest.h
  30. +56 −44 Classes/S3/ASIS3ObjectRequest.m
  31. +19 −3 Classes/S3/ASIS3Request.h
  32. +33 −5 Classes/S3/ASIS3Request.m
  33. +7 −3 Classes/S3/ASIS3ServiceRequest.m
  34. +16 −0 Classes/Tests/ASIDataCompressorTests.h
  35. +179 −0 Classes/Tests/ASIDataCompressorTests.m
  36. +1 −0 Classes/Tests/ASIDownloadCacheTests.h
  37. +258 −76 Classes/Tests/ASIDownloadCacheTests.m
  38. +21 −0 Classes/Tests/ASIFormDataRequestTests.m
  39. +2 −8 Classes/Tests/ASIHTTPRequestTests.h
  40. +330 −88 Classes/Tests/ASIHTTPRequestTests.m
  41. +80 −19 Classes/Tests/ASINetworkQueueTests.m
  42. +2 −0 Classes/Tests/ASIS3RequestTests.h
  43. +109 −12 Classes/Tests/ASIS3RequestTests.m
  44. +1 −1 Classes/Tests/ASITestCase.h
  45. +16 −0 Classes/Tests/ASIWebPageRequestTests.h
  46. +41 −0 Classes/Tests/ASIWebPageRequestTests.m
  47. +16 −0 Classes/Tests/BlocksTests.h
  48. +105 −0 Classes/Tests/BlocksTests.m
  49. +1 −1 Classes/Tests/ClientCertificateTests.m
  50. +9 −0 Classes/Tests/PerformanceTests.m
  51. +7 −0 Classes/Tests/ProxyTests.m
  52. +7 −0 Classes/Tests/StressTests.m
  53. +25 −1 DONORS
  54. +0 −1 External/GHUnit
  55. +3 −0 External/GHUnit/README-GHUnit
  56. +5 −5 External/Reachability/Reachability.m
  57. +1 −1 LICENSE
  58. +8 −0 Mac Sample/AppDelegate.h
  59. +75 −6 Mac Sample/AppDelegate.m
  60. +1,444 −155 Mac Sample/English.lproj/MainMenu.xib
  61. +82 −84 Mac.xcodeproj/project.pbxproj
  62. +13 −5 README.textile
  63. +0 −3 clang.sh
  64. +14 −4 iPhone Sample/AuthenticationViewController.m
  65. +82 −0 iPhone Sample/GHUnitIOSTestMain.m
  66. +12 −4 iPhone Sample/QueueViewController.m
  67. +18 −0 iPhone Sample/RequestProgressCell.h
  68. +40 −0 iPhone Sample/RequestProgressCell.m
  69. +52 −11 iPhone Sample/Resources/iPhoneMainWindow.xib
  70. +9 −2 iPhone Sample/RootViewController.m
  71. +35 −0 iPhone Sample/SampleViewController.m
  72. +4 −27 iPhone Sample/SynchronousViewController.m
  73. +32 −4 iPhone Sample/UploadViewController.m
  74. +26 −0 iPhone Sample/WebPageViewController.h
  75. +330 −0 iPhone Sample/WebPageViewController.m
  76. +7 −0 iPhone Sample/iPadInfo.plist
  77. +3 −0 iPhone Sample/iPhone_Prefix.pch
  78. +156 −134 iPhone.xcodeproj/project.pbxproj
  79. +1 −1 strict.xcconfig
View
@@ -9,3 +9,4 @@ build
profile
*.pbxuser
*.mode1v3
+External/GHUnit/*
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+
+# This script fetches a pre-compiled copy of the iOS GHUnit.framework, if one isn't already in the External/GHUnit folder
+# This replaces the old system, where GHUnit was included as a git submodule, because:
+# a) git submodules confuse people (including me)
+# b) GHUnit seems to be tricky to build without warnings
+# The pre-compiled frameworks on allseeing-i.com were taken directly from those on the GHUnit downloads page on GitHub
+# If you'd rather build GHUnit yourself, simply grab a copy from http://github.com/gabriel/gh-unit and drop your built framework into External/GHUnit
+
+require 'net/http'
+if (!File.exists?('External/GHUnit/GHUnitIOS.framework'))
+ `curl -s http://allseeing-i.com/ASIHTTPRequest/GHUnit/GHUnit-IOS.zip > External/GHUnit/GHUnit-IOS.zip`
+ `unzip External/GHUnit/GHUnit-IOS.zip -d External/GHUnit/ & rm External/GHUnit/GHUnit-IOS.zip`
+end
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+
+# This script fetches a pre-compiled copy of the Mac GHUnit.framework, if one isn't already in the External/GHUnit folder
+# This replaces the old system, where GHUnit was included as a git submodule, because:
+# a) git submodules confuse people (including me)
+# b) GHUnit seems to be tricky to build without warnings
+# The pre-compiled frameworks on allseeing-i.com were taken directly from those on the GHUnit downloads page on GitHub
+# If you'd rather build GHUnit yourself, simply grab a copy from http://github.com/gabriel/gh-unit and drop your built framework into External/GHUnit
+
+require 'net/http'
+if (!File.exists?('External/GHUnit/GHUnit.framework'))
+ `curl -s http://allseeing-i.com/ASIHTTPRequest/GHUnit/GHUnit-Mac.zip > External/GHUnit/GHUnit-Mac.zip`
+ `unzip External/GHUnit/GHUnit-Mac.zip -d External/GHUnit/ & rm External/GHUnit/GHUnit-Mac.zip`
+end
@@ -3,8 +3,8 @@
# This script sets a version number for ASIHTTPRequest based on the last commit, and is run when you build one of the targets in the Xcode projects that come with ASIHTTPRequest
# It only really needs to run on my computer, not on yours... :)
require 'find'
-if (File.exists?('/opt/local/bin/git'))
- newversion = `/opt/local/bin/git describe --tags`.match(/(v([0-9]+)(\.([0-9]+)){1,}-([0-9]+))/).to_s.gsub(/[0-9]+$/){|commit| (commit.to_i + 1).to_s}+Time.now.strftime(" %Y-%m-%d")
+if (File.exists?('.git') && File.directory?('.git') && File.exists?('/usr/local/bin/git'))
+ newversion = `/usr/local/bin/git describe --tags`.match(/(v([0-9]+)(\.([0-9]+)){1,}-([0-9]+))/).to_s.gsub(/[0-9]+$/){|commit| (commit.to_i + 1).to_s}+Time.now.strftime(" %Y-%m-%d")
buffer = File.new('Classes/ASIHTTPRequest.m','r').read
if !buffer.match(/#{Regexp.quote(newversion)}/)
buffer = buffer.sub(/(NSString \*ASIHTTPRequestVersion = @\")(.*)(";)/,'\1'+newversion+'\3');
@@ -37,6 +37,10 @@ - (void)showTitle;
- (void)show;
- (NSArray *)requestsRequiringTheseCredentials;
- (void)presentNextDialog;
+- (void)keyboardWillShow:(NSNotification *)notification;
+- (void)orientationChanged:(NSNotification *)notification;
+- (void)cancelAuthenticationFromDialog:(id)sender;
+- (void)loginWithCredentialsFromDialog:(id)sender;
@property (retain) UITableView *tableView;
@end
@@ -51,20 +55,20 @@ + (void)initialize
}
}
-+ (void)presentAuthenticationDialogForRequest:(ASIHTTPRequest *)request
++ (void)presentAuthenticationDialogForRequest:(ASIHTTPRequest *)theRequest
{
// No need for a lock here, this will always be called on the main thread
if (!sharedDialog) {
sharedDialog = [[self alloc] init];
- [sharedDialog setRequest:request];
- if ([request authenticationNeeded] == ASIProxyAuthenticationNeeded) {
+ [sharedDialog setRequest:theRequest];
+ if ([theRequest authenticationNeeded] == ASIProxyAuthenticationNeeded) {
[sharedDialog setType:ASIProxyAuthenticationType];
} else {
[sharedDialog setType:ASIStandardAuthenticationType];
}
[sharedDialog show];
} else {
- [requestsNeedingAuthentication addObject:request];
+ [requestsNeedingAuthentication addObject:theRequest];
}
}
@@ -129,7 +133,7 @@ - (void)orientationChanged:(NSNotification *)notification
{
[self showTitle];
- UIDeviceOrientation o = [[UIApplication sharedApplication] statusBarOrientation];
+ UIInterfaceOrientation o = [[UIApplication sharedApplication] statusBarOrientation];
CGFloat angle = 0;
switch (o) {
case UIDeviceOrientationLandscapeLeft: angle = 90; break;
@@ -149,11 +153,11 @@ - (void)orientationChanged:(NSNotification *)notification
}
CGAffineTransform previousTransform = self.view.layer.affineTransform;
- CGAffineTransform newTransform = CGAffineTransformMakeRotation(angle * M_PI / 180.0);
+ CGAffineTransform newTransform = CGAffineTransformMakeRotation((CGFloat)(angle * M_PI / 180.0));
// Reset the transform so we can set the size
self.view.layer.affineTransform = CGAffineTransformIdentity;
- self.view.frame = (CGRect){0,0,f.size};
+ self.view.frame = (CGRect){ { 0, 0 }, f.size};
// Revert to the previous transform for correct animation
self.view.layer.affineTransform = previousTransform;
@@ -165,7 +169,7 @@ - (void)orientationChanged:(NSNotification *)notification
self.view.layer.affineTransform = newTransform;
// Fix the view origin
- self.view.frame = (CGRect){f.origin.x,f.origin.y,self.view.frame.size};
+ self.view.frame = (CGRect){ { f.origin.x, f.origin.y },self.view.frame.size};
[UIView commitAnimations];
}
@@ -220,7 +224,7 @@ - (void)viewDidDisappear:(BOOL)animated
[self retain];
[sharedDialog release];
sharedDialog = nil;
- [self presentNextDialog];
+ [self performSelector:@selector(presentNextDialog) withObject:nil afterDelay:0];
[self release];
}
@@ -450,7 +454,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return 2;
View
@@ -9,14 +9,40 @@
#import <Foundation/Foundation.h>
@class ASIHTTPRequest;
+// Cache policies control the behaviour of a cache and how requests use the cache
+// When setting a cache policy, you can use a combination of these values as a bitmask
+// For example: [request setCachePolicy:ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy|ASIDoNotWriteToCacheCachePolicy];
+// Note that some of the behaviours below are mutally exclusive - you cannot combine ASIAskServerIfModifiedWhenStaleCachePolicy and ASIAskServerIfModifiedCachePolicy, for example.
typedef enum _ASICachePolicy {
- ASIDefaultCachePolicy = 0,
- ASIIgnoreCachePolicy = 1,
- ASIReloadIfDifferentCachePolicy = 2,
- ASIOnlyLoadIfNotCachedCachePolicy = 3,
- ASIUseCacheIfLoadFailsCachePolicy = 4
+
+ // The default cache policy. When you set a request to use this, it will use the cache's defaultCachePolicy
+ // ASIDownloadCache's default cache policy is 'ASIAskServerIfModifiedWhenStaleCachePolicy'
+ ASIUseDefaultCachePolicy = 0,
+
+ // Tell the request not to read from the cache
+ ASIDoNotReadFromCacheCachePolicy = 1,
+
+ // The the request not to write to the cache
+ ASIDoNotWriteToCacheCachePolicy = 2,
+
+ // Ask the server if there is an updated version of this resource (using a conditional GET) ONLY when the cached data is stale
+ ASIAskServerIfModifiedWhenStaleCachePolicy = 4,
+
+ // Always ask the server if there is an updated version of this resource (using a conditional GET)
+ ASIAskServerIfModifiedCachePolicy = 8,
+
+ // If cached data exists, use it even if it is stale. This means requests will not talk to the server unless the resource they are requesting is not in the cache
+ ASIOnlyLoadIfNotCachedCachePolicy = 16,
+
+ // If cached data exists, use it even if it is stale. If cached data does not exist, stop (will not set an error on the request)
+ ASIDontLoadCachePolicy = 32,
+
+ // Specifies that cached data may be used if the request fails. If cached data is used, the request will succeed without error. Usually used in combination with other options above.
+ ASIFallbackToCacheIfLoadFailsCachePolicy = 64
} ASICachePolicy;
+// Cache storage policies control whether cached data persists between application launches (ASICachePermanentlyCacheStoragePolicy) or not (ASICacheForSessionDurationCacheStoragePolicy)
+// Calling [ASIHTTPRequest clearSession] will remove any data stored using ASICacheForSessionDurationCacheStoragePolicy
typedef enum _ASICacheStoragePolicy {
ASICacheForSessionDurationCacheStoragePolicy = 0,
ASICachePermanentlyCacheStoragePolicy = 1
@@ -27,10 +53,19 @@ typedef enum _ASICacheStoragePolicy {
@required
-// Should return the cache policy that will be used when requests have their cache policy set to ASIDefaultCachePolicy
+// Should return the cache policy that will be used when requests have their cache policy set to ASIUseDefaultCachePolicy
- (ASICachePolicy)defaultCachePolicy;
-// Should Remove cached data for a particular request
+// Returns the date a cached response should expire on. Pass a non-zero max age to specify a custom date.
+- (NSDate *)expiryDateForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge;
+
+// Updates cached response headers with a new expiry date. Pass a non-zero max age to specify a custom date.
+- (void)updateExpiryForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge;
+
+// Looks at the request's cache policy and any cached headers to determine if the cache data is still valid
+- (BOOL)canUseCachedDataForRequest:(ASIHTTPRequest *)request;
+
+// Removes cached data for a particular request
- (void)removeCachedDataForRequest:(ASIHTTPRequest *)request;
// Should return YES if the cache considers its cached response current for the request
@@ -41,16 +76,28 @@ typedef enum _ASICacheStoragePolicy {
// When a non-zero maxAge is passed, it should be used as the expiry time for the cached response
- (void)storeResponseForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge;
-// Should return an NSDictionary of cached headers for the passed request, if it is stored in the cache
-- (NSDictionary *)cachedHeadersForRequest:(ASIHTTPRequest *)request;
+// Removes cached data for a particular url
+- (void)removeCachedDataForURL:(NSURL *)url;
+
+// Should return an NSDictionary of cached headers for the passed URL, if it is stored in the cache
+- (NSDictionary *)cachedResponseHeadersForURL:(NSURL *)url;
-// Should return the cached body of a response for the passed request, if it is stored in the cache
-- (NSData *)cachedResponseDataForRequest:(ASIHTTPRequest *)request;
+// Should return the cached body of a response for the passed URL, if it is stored in the cache
+- (NSData *)cachedResponseDataForURL:(NSURL *)url;
-// Same as the above, but returns a path to the cached response body instead
-- (NSString *)pathToCachedResponseDataForRequest:(ASIHTTPRequest *)request;
-- (NSString *)pathToCachedResponseHeadersForRequest:(ASIHTTPRequest *)request;
+// Returns a path to the cached response data, if it exists
+- (NSString *)pathToCachedResponseDataForURL:(NSURL *)url;
+
+// Returns a path to the cached response headers, if they url
+- (NSString *)pathToCachedResponseHeadersForURL:(NSURL *)url;
+
+// Returns the location to use to store cached response headers for a particular request
+- (NSString *)pathToStoreCachedResponseHeadersForRequest:(ASIHTTPRequest *)request;
+
+// Returns the location to use to store a cached response body for a particular request
+- (NSString *)pathToStoreCachedResponseDataForRequest:(ASIHTTPRequest *)request;
// Clear cached data stored for the passed storage policy
- (void)clearCachedResponsesForStoragePolicy:(ASICacheStoragePolicy)cachePolicy;
+
@end
@@ -0,0 +1,42 @@
+//
+// ASIDataCompressor.h
+// Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
+//
+// Created by Ben Copsey on 17/08/2010.
+// Copyright 2010 All-Seeing Interactive. All rights reserved.
+//
+
+// This is a helper class used by ASIHTTPRequest to handle deflating (compressing) data in memory and on disk
+// You may also find it helpful if you need to deflate data and files yourself - see the class methods below
+// Most of the zlib stuff is based on the sample code by Mark Adler available at http://zlib.net
+
+#import <Foundation/Foundation.h>
+#import <zlib.h>
+
+@interface ASIDataCompressor : NSObject {
+ BOOL streamReady;
+ z_stream zStream;
+}
+
+// Convenience constructor will call setupStream for you
++ (id)compressor;
+
+// Compress the passed chunk of data
+// Passing YES for shouldFinish will finalize the deflated data - you must pass YES when you are on the last chunk of data
+- (NSData *)compressBytes:(Bytef *)bytes length:(NSUInteger)length error:(NSError **)err shouldFinish:(BOOL)shouldFinish;
+
+// Convenience method - pass it some data, and you'll get deflated data back
++ (NSData *)compressData:(NSData*)uncompressedData error:(NSError **)err;
+
+// Convenience method - pass it a file containing the data to compress in sourcePath, and it will write deflated data to destinationPath
++ (BOOL)compressDataFromFile:(NSString *)sourcePath toFile:(NSString *)destinationPath error:(NSError **)err;
+
+// Sets up zlib to handle the inflating. You only need to call this yourself if you aren't using the convenience constructor 'compressor'
+- (NSError *)setupStream;
+
+// Tells zlib to clean up. You need to call this if you need to cancel deflating part way through
+// If deflating finishes or fails, this method will be called automatically
+- (NSError *)closeStream;
+
+@property (assign, readonly) BOOL streamReady;
+@end
Oops, something went wrong.

0 comments on commit 678121f

Please sign in to comment.