Ben Copsey

Minor cleanups and fix urls

@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 NSString *path = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"bigfile"]; 22 NSString *path = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"bigfile"];
23 [data writeToFile:path atomically:NO]; 23 [data writeToFile:path atomically:NO];
24 24
25 - ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://asi/asi-http-request/tests/post"]] autorelease]; 25 + ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http:/http://allseeing-i.com/asi-http-request/tests/post"]] autorelease];
26 [request setPostValue:@"foo" forKey:@"post_var"]; 26 [request setPostValue:@"foo" forKey:@"post_var"];
27 [request setFile:path forKey:@"file"]; 27 [request setFile:path forKey:@"file"];
28 [request start]; 28 [request start];
@@ -62,7 +62,6 @@ static NSRecursiveLock *progressLock; @@ -62,7 +62,6 @@ static NSRecursiveLock *progressLock;
62 outputStream = nil; 62 outputStream = nil;
63 requestAuthentication = NULL; 63 requestAuthentication = NULL;
64 haveBuiltPostBody = NO; 64 haveBuiltPostBody = NO;
65 - //credentials = NULL;  
66 request = NULL; 65 request = NULL;
67 responseHeaders = nil; 66 responseHeaders = nil;
68 [self setTimeOutSeconds:10]; 67 [self setTimeOutSeconds:10];
@@ -226,10 +225,6 @@ static NSRecursiveLock *progressLock; @@ -226,10 +225,6 @@ static NSRecursiveLock *progressLock;
226 CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)header, (CFStringRef)[requestHeaders objectForKey:header]); 225 CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)header, (CFStringRef)[requestHeaders objectForKey:header]);
227 } 226 }
228 227
229 - //NSData *d = (NSData *)CFHTTPMessageCopySerializedMessage(request);  
230 - //NSLog(@"%@",[[[NSString alloc] initWithBytes:[d bytes] length:[d length] encoding:NSUTF8StringEncoding] autorelease]);  
231 -  
232 -  
233 // If this is a post request and we have data to send, add it to the request 228 // If this is a post request and we have data to send, add it to the request
234 if ([self postBody]) { 229 if ([self postBody]) {
235 CFHTTPMessageSetBody(request, (CFDataRef)postBody); 230 CFHTTPMessageSetBody(request, (CFDataRef)postBody);
@@ -388,7 +383,6 @@ static NSRecursiveLock *progressLock; @@ -388,7 +383,6 @@ static NSRecursiveLock *progressLock;
388 383
389 - (void)updateProgressIndicators 384 - (void)updateProgressIndicators
390 { 385 {
391 -  
392 //Only update progress if this isn't a HEAD request used to preset the content-length 386 //Only update progress if this isn't a HEAD request used to preset the content-length
393 if (!mainRequest) { 387 if (!mainRequest) {
394 if (showAccurateProgress || (complete && !updatedProgress)) { 388 if (showAccurateProgress || (complete && !updatedProgress)) {
@@ -396,7 +390,6 @@ static NSRecursiveLock *progressLock; @@ -396,7 +390,6 @@ static NSRecursiveLock *progressLock;
396 [self updateDownloadProgress]; 390 [self updateDownloadProgress];
397 } 391 }
398 } 392 }
399 -  
400 } 393 }
401 394
402 395
@@ -519,7 +512,7 @@ static NSRecursiveLock *progressLock; @@ -519,7 +512,7 @@ static NSRecursiveLock *progressLock;
519 { 512 {
520 unsigned long long bytesReadSoFar = totalBytesRead; 513 unsigned long long bytesReadSoFar = totalBytesRead;
521 514
522 - //We won't update download progress until we've examined the headers, since we might need to authenticate 515 + // We won't update download progress until we've examined the headers, since we might need to authenticate
523 if (responseHeaders) { 516 if (responseHeaders) {
524 517
525 if (bytesReadSoFar > lastBytesRead) { 518 if (bytesReadSoFar > lastBytesRead) {
@@ -528,8 +521,7 @@ static NSRecursiveLock *progressLock; @@ -528,8 +521,7 @@ static NSRecursiveLock *progressLock;
528 521
529 if (downloadProgressDelegate) { 522 if (downloadProgressDelegate) {
530 523
531 - 524 + // We're using a progress queue or compatible controller to handle progress
532 - //We're using a progress queue or compatible controller to handle progress  
533 if ([downloadProgressDelegate respondsToSelector:@selector(incrementDownloadProgressBy:)]) { 525 if ([downloadProgressDelegate respondsToSelector:@selector(incrementDownloadProgressBy:)]) {
534 526
535 NSAutoreleasePool *thePool = [[NSAutoreleasePool alloc] init]; 527 NSAutoreleasePool *thePool = [[NSAutoreleasePool alloc] init];
@@ -554,7 +546,7 @@ static NSRecursiveLock *progressLock; @@ -554,7 +546,7 @@ static NSRecursiveLock *progressLock;
554 546
555 [thePool release]; 547 [thePool release];
556 548
557 - //We aren't using a queue, we should just set progress of the indicator to 0 549 + // We aren't using a queue, we should just set progress of the indicator to 0
558 } else if (contentLength > 0) { 550 } else if (contentLength > 0) {
559 [ASIHTTPRequest setProgress:(double)(bytesReadSoFar/contentLength) forProgressIndicator:downloadProgressDelegate]; 551 [ASIHTTPRequest setProgress:(double)(bytesReadSoFar/contentLength) forProgressIndicator:downloadProgressDelegate];
560 } 552 }
@@ -568,7 +560,7 @@ static NSRecursiveLock *progressLock; @@ -568,7 +560,7 @@ static NSRecursiveLock *progressLock;
568 -(void)removeUploadProgressSoFar 560 -(void)removeUploadProgressSoFar
569 { 561 {
570 562
571 - //We're using a progress queue or compatible controller to handle progress 563 + // We're using a progress queue or compatible controller to handle progress
572 if ([uploadProgressDelegate respondsToSelector:@selector(decrementUploadProgressBy:)]) { 564 if ([uploadProgressDelegate respondsToSelector:@selector(decrementUploadProgressBy:)]) {
573 unsigned long long value = 0-lastBytesSent; 565 unsigned long long value = 0-lastBytesSent;
574 SEL selector = @selector(decrementUploadProgressBy:); 566 SEL selector = @selector(decrementUploadProgressBy:);
@@ -579,7 +571,7 @@ static NSRecursiveLock *progressLock; @@ -579,7 +571,7 @@ static NSRecursiveLock *progressLock;
579 [invocation setArgument:&value atIndex:2]; 571 [invocation setArgument:&value atIndex:2];
580 [invocation invoke]; 572 [invocation invoke];
581 573
582 - //We aren't using a queue, we should just set progress of the indicator to 0 574 + // We aren't using a queue, we should just set progress of the indicator to 0
583 } else { 575 } else {
584 [ASIHTTPRequest setProgress:0 forProgressIndicator:uploadProgressDelegate]; 576 [ASIHTTPRequest setProgress:0 forProgressIndicator:uploadProgressDelegate];
585 } 577 }
@@ -598,11 +590,11 @@ static NSRecursiveLock *progressLock; @@ -598,11 +590,11 @@ static NSRecursiveLock *progressLock;
598 NSMethodSignature *signature = [[indicator class] instanceMethodSignatureForSelector:selector]; 590 NSMethodSignature *signature = [[indicator class] instanceMethodSignatureForSelector:selector];
599 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; 591 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
600 [invocation setSelector:selector]; 592 [invocation setSelector:selector];
601 - float progressFloat = (float)progress; //UIProgressView wants a float for the progress parameter 593 + float progressFloat = (float)progress; // UIProgressView wants a float for the progress parameter
602 [invocation setArgument:&progressFloat atIndex:2]; 594 [invocation setArgument:&progressFloat atIndex:2];
603 [invocation invokeWithTarget:indicator]; 595 [invocation invokeWithTarget:indicator];
604 596
605 - //If we're running in the main thread, update the progress straight away. Otherwise, it's not that urgent 597 + // If we're running in the main thread, update the progress straight away. Otherwise, it's not that urgent
606 [invocation performSelectorOnMainThread:@selector(invokeWithTarget:) withObject:indicator waitUntilDone:[NSThread isMainThread]]; 598 [invocation performSelectorOnMainThread:@selector(invokeWithTarget:) withObject:indicator waitUntilDone:[NSThread isMainThread]];
607 599
608 600
@@ -667,10 +659,10 @@ static NSRecursiveLock *progressLock; @@ -667,10 +659,10 @@ static NSRecursiveLock *progressLock;
667 // Is the server response a challenge for credentials? 659 // Is the server response a challenge for credentials?
668 isAuthenticationChallenge = (responseStatusCode == 401); 660 isAuthenticationChallenge = (responseStatusCode == 401);
669 661
670 - //We won't reset the download progress delegate if we got an authentication challenge 662 + // We won't reset the download progress delegate if we got an authentication challenge
671 if (!isAuthenticationChallenge) { 663 if (!isAuthenticationChallenge) {
672 664
673 - //See if we got a Content-length header 665 + // See if we got a Content-length header
674 NSString *cLength = [responseHeaders valueForKey:@"Content-Length"]; 666 NSString *cLength = [responseHeaders valueForKey:@"Content-Length"];
675 if (cLength) { 667 if (cLength) {
676 contentLength = CFStringGetIntValue((CFStringRef)cLength); 668 contentLength = CFStringGetIntValue((CFStringRef)cLength);
@@ -682,15 +674,16 @@ static NSRecursiveLock *progressLock; @@ -682,15 +674,16 @@ static NSRecursiveLock *progressLock;
682 } 674 }
683 } 675 }
684 676
685 - //Handle cookies 677 + // Handle cookies
686 NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:responseHeaders forURL:url]; 678 NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:responseHeaders forURL:url];
687 [self setResponseCookies:cookies]; 679 [self setResponseCookies:cookies];
688 680
689 if (useCookiePersistance) { 681 if (useCookiePersistance) {
690 - //Store cookies in global persistent store 682 +
  683 + // Store cookies in global persistent store
691 [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:cookies forURL:url mainDocumentURL:nil]; 684 [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:cookies forURL:url mainDocumentURL:nil];
692 685
693 - //We also keep any cookies in the sessionCookies array, so that we have a reference to them if we need to remove them later 686 + // We also keep any cookies in the sessionCookies array, so that we have a reference to them if we need to remove them later
694 if (!sessionCookies) { 687 if (!sessionCookies) {
695 [ASIHTTPRequest setSessionCookies:[[[NSMutableArray alloc] init] autorelease]]; 688 [ASIHTTPRequest setSessionCookies:[[[NSMutableArray alloc] init] autorelease]];
696 NSHTTPCookie *cookie; 689 NSHTTPCookie *cookie;
@@ -711,7 +704,8 @@ static NSRecursiveLock *progressLock; @@ -711,7 +704,8 @@ static NSRecursiveLock *progressLock;
711 - (void)saveCredentialsToKeychain:(NSMutableDictionary *)newCredentials 704 - (void)saveCredentialsToKeychain:(NSMutableDictionary *)newCredentials
712 { 705 {
713 NSURLCredential *authenticationCredentials = [NSURLCredential credentialWithUser:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationUsername] 706 NSURLCredential *authenticationCredentials = [NSURLCredential credentialWithUser:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationUsername]
714 - password:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationPassword] persistence:NSURLCredentialPersistencePermanent]; 707 + password:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationPassword]
  708 + persistence:NSURLCredentialPersistencePermanent];
715 709
716 if (authenticationCredentials) { 710 if (authenticationCredentials) {
717 [ASIHTTPRequest saveCredentials:authenticationCredentials forHost:[url host] port:[[url port] intValue] protocol:[url scheme] realm:authenticationRealm]; 711 [ASIHTTPRequest saveCredentials:authenticationCredentials forHost:[url host] port:[[url port] intValue] protocol:[url scheme] realm:authenticationRealm];
@@ -958,8 +952,6 @@ static NSRecursiveLock *progressLock; @@ -958,8 +952,6 @@ static NSRecursiveLock *progressLock;
958 952
959 - (void)handleStreamComplete 953 - (void)handleStreamComplete
960 { 954 {
961 -  
962 -  
963 //Try to read the headers (if this is a HEAD request handleBytesAvailable available may not be called) 955 //Try to read the headers (if this is a HEAD request handleBytesAvailable available may not be called)
964 if (!responseHeaders) { 956 if (!responseHeaders) {
965 if ([self readResponseHeadersReturningAuthenticationFailure]) { 957 if ([self readResponseHeadersReturningAuthenticationFailure]) {
@@ -205,7 +205,6 @@ @@ -205,7 +205,6 @@
205 { 205 {
206 complete = YES; 206 complete = YES;
207 } 207 }
208 -  
209 208
210 209
211 210