Ben Copsey

Stream errors now properly cancel requests, preventing a crash when tracking upload progress

Add missing nil terminator in testRequestMethod
Thanks to Michael Krause for contributing these fixes and the test!
... ... @@ -166,10 +166,11 @@ static NSError *ASIUnableToCreateRequestError;
- (void)cancel
{
[super cancel];
[self failWithError:ASIRequestCancelledError];
[self cancelLoad];
complete = YES;
[super cancel];
}
... ... @@ -516,6 +517,7 @@ static NSError *ASIUnableToCreateRequestError;
{
[cancelledLock lock];
if ([self isCancelled]) {
[cancelledLock unlock];
return;
}
unsigned long long byteCount = [[(NSNumber *)CFReadStreamCopyProperty (readStream, kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease] unsignedLongLongValue];
... ... @@ -1160,7 +1162,9 @@ static NSError *ASIUnableToCreateRequestError;
{
NSError *underlyingError = [(NSError *)CFReadStreamCopyError(readStream) autorelease];
[super cancel];
[self cancelLoad];
complete = YES;
if (!error) { // We may already have handled this error
... ...
... ... @@ -99,7 +99,7 @@
- (void)testRequestMethod
{
NSURL *url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/request-method"] autorelease];
NSArray *methods = [[[NSArray alloc] initWithObjects:@"GET",@"POST",@"PUT",@"DELETE"] autorelease];
NSArray *methods = [[[NSArray alloc] initWithObjects:@"GET",@"POST",@"PUT",@"DELETE", nil] autorelease];
for (NSString *method in methods) {
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setRequestMethod:method];
... ... @@ -442,9 +442,8 @@
- (void)testNTLMAuthentication
{
/*
If you want to run this test, set your hostname, username, password and domain below.
*/
// If you want to run this test, set your hostname, username, password and domain below.
NSString *theURL = @"";
NSString *username = @"";
NSString *password = @"";
... ...
... ... @@ -22,6 +22,7 @@
- (void)testFailureCancelsOtherRequests;
- (void)testProgress;
- (void)testProgressWithAuthentication;
- (void)testWithNoListener;
- (void)setProgress:(float)newProgress;
... ...
... ... @@ -265,5 +265,34 @@ static CFStringRef ASIHTTPRequestTestsRunMode = CFSTR("ASIHTTPRequestTestsRunMod
}
//Connect to a port the server isn't listening on, and the read stream won't be created (Test + Fix contributed by Michael Krause)
- (void)testWithNoListener
{
complete = NO;
networkQueue = [[ASINetworkQueue alloc] init];
[networkQueue setDownloadProgressDelegate:self];
[networkQueue setDelegate:self];
[networkQueue setShowAccurateProgress:YES];
[networkQueue setQueueDidFinishSelector:@selector(queueFinished:)];
NSURL *url;
url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com:9999/i/logo.png"] autorelease];
ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[networkQueue addOperation:request1];
[networkQueue go];
while (!complete) {
CFRunLoopRunInMode(ASIHTTPRequestTestsRunMode,0.25,YES);
}
[networkQueue waitUntilAllOperationsAreFinished];
BOOL success = YES;
GHAssertTrue(success,@"Should not have crashed");
[networkQueue release];
}
@end
... ...