Ben Copsey

Added [request tag] (closes gh-179)

Updated SSL test to handle updated error message
... ... @@ -346,8 +346,9 @@ typedef void (^ASIDataBlock)(NSData *data);
// Tells ASIHTTPRequest not to delete partial downloads, and allows it to use an existing file to resume a download. Defaults to NO.
BOOL allowResumeForFileDownloads;
// Custom user information associated with the request
// Custom user information associated with the request (not sent to the server)
NSDictionary *userInfo;
NSInteger tag;
// Use HTTP 1.0 rather than 1.1 (defaults to false)
BOOL useHTTPVersionOne;
... ... @@ -952,6 +953,7 @@ typedef void (^ASIDataBlock)(NSData *data);
@property (assign) BOOL allowCompressedResponse;
@property (assign) BOOL allowResumeForFileDownloads;
@property (retain) NSDictionary *userInfo;
@property (assign) NSInteger tag;
@property (retain) NSString *postBodyFilePath;
@property (assign) BOOL shouldStreamPostDataFromDisk;
@property (assign) BOOL didCreateTemporaryPostDataFile;
... ...
... ... @@ -3840,6 +3840,7 @@ static NSOperationQueue *sharedQueue = nil;
[newRequest setDefaultResponseEncoding:[self defaultResponseEncoding]];
[newRequest setAllowResumeForFileDownloads:[self allowResumeForFileDownloads]];
[newRequest setUserInfo:[[[self userInfo] copyWithZone:zone] autorelease]];
[newRequest setTag:[self tag]];
[newRequest setUseHTTPVersionOne:[self useHTTPVersionOne]];
[newRequest setShouldRedirect:[self shouldRedirect]];
[newRequest setValidatesSecureCertificate:[self validatesSecureCertificate]];
... ... @@ -4728,6 +4729,7 @@ static NSOperationQueue *sharedQueue = nil;
@synthesize allowCompressedResponse;
@synthesize allowResumeForFileDownloads;
@synthesize userInfo;
@synthesize tag;
@synthesize postBodyFilePath;
@synthesize compressedPostBodyFilePath;
@synthesize postBodyWriteStream;
... ...
... ... @@ -1389,7 +1389,7 @@
GHAssertNotNil([request error],@"Failed to generate an error for a self-signed certificate (Will fail on the second run in the same session!)");
// Just for testing the request generated a custom error description - don't do this! You should look at the domain / code of the underlyingError in your own programs.
BOOL success = ([[[request error] localizedDescription] isEqualToString:@"A connection failure occurred: SSL problem (possibly a bad/expired/self-signed certificate)"]);
BOOL success = ([[[request error] localizedDescription] rangeOfString:@"SSL problem"].location != NSNotFound);
GHAssertTrue(success,@"Generated the wrong error for a self signed cert");
// Turn off certificate validation, and try again
... ... @@ -1561,28 +1561,28 @@
- (void)testAsynchronous
{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/first"]];
[request setUserInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:@"RequestNumber"]];
[request setTag:1];
[request setDidFailSelector:@selector(asyncFail:)];
[request setDidFinishSelector:@selector(asyncSuccess:)];
[request setDelegate:self];
[request startAsynchronous];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/second"]];
[request setUserInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:2] forKey:@"RequestNumber"]];
[request setTag:2];
[request setDidFailSelector:@selector(asyncFail:)];
[request setDidFinishSelector:@selector(asyncSuccess:)];
[request setDelegate:self];
[request startAsynchronous];
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/third"]];
[request setUserInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:3] forKey:@"RequestNumber"]];
[request setTag:3];
[request setDidFailSelector:@selector(asyncFail:)];
[request setDidFinishSelector:@selector(asyncSuccess:)];
[request setDelegate:self];
[request startAsynchronous];
request = [ASIHTTPRequest requestWithURL:nil];
[request setUserInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:4] forKey:@"RequestNumber"]];
[request setTag:4];
[request setDidFailSelector:@selector(asyncFail:)];
[request setDidFinishSelector:@selector(asyncSuccess:)];
[request setDelegate:self];
... ... @@ -1592,18 +1592,16 @@
- (void)asyncFail:(ASIHTTPRequest *)request
{
int requestNumber = [[[request userInfo] objectForKey:@"RequestNumber"] intValue];
BOOL success = (requestNumber == 4);
BOOL success = ([request tag] == 4);
GHAssertTrue(success,@"Wrong request failed");
}
- (void)asyncSuccess:(ASIHTTPRequest *)request
{
int requestNumber = [[[request userInfo] objectForKey:@"RequestNumber"] intValue];
BOOL success = (requestNumber != 4);
BOOL success = ([request tag] != 4);
GHAssertTrue(success,@"Request succeeded when it should have failed");
switch (requestNumber) {
switch ([request tag]) {
case 1:
success = [[request responseString] isEqualToString:@"This is the expected content for the first string"];
break;
... ...