Skip to content

Commit

Permalink
Minor cleanups and fix urls
Browse files Browse the repository at this point in the history
  • Loading branch information
pokeb committed Nov 11, 2008
1 parent b8f5f36 commit 844d691
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
2 changes: 1 addition & 1 deletion ASIFormDataRequestTests.m
Expand Up @@ -22,7 +22,7 @@ - (void)testPostWithFileUpload
NSString *path = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"bigfile"];
[data writeToFile:path atomically:NO];

ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://asi/asi-http-request/tests/post"]] autorelease];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http:/http://allseeing-i.com/asi-http-request/tests/post"]] autorelease];
[request setPostValue:@"foo" forKey:@"post_var"];
[request setFile:path forKey:@"file"];
[request start];
Expand Down
38 changes: 15 additions & 23 deletions ASIHTTPRequest.m
Expand Up @@ -62,7 +62,6 @@ - (id)initWithURL:(NSURL *)newURL
outputStream = nil;
requestAuthentication = NULL;
haveBuiltPostBody = NO;
//credentials = NULL;
request = NULL;
responseHeaders = nil;
[self setTimeOutSeconds:10];
Expand Down Expand Up @@ -226,10 +225,6 @@ - (void)main
CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)header, (CFStringRef)[requestHeaders objectForKey:header]);
}

//NSData *d = (NSData *)CFHTTPMessageCopySerializedMessage(request);
//NSLog(@"%@",[[[NSString alloc] initWithBytes:[d bytes] length:[d length] encoding:NSUTF8StringEncoding] autorelease]);


// If this is a post request and we have data to send, add it to the request
if ([self postBody]) {
CFHTTPMessageSetBody(request, (CFDataRef)postBody);
Expand Down Expand Up @@ -388,15 +383,13 @@ - (void)cancelLoad

- (void)updateProgressIndicators
{

//Only update progress if this isn't a HEAD request used to preset the content-length
if (!mainRequest) {
if (showAccurateProgress || (complete && !updatedProgress)) {
[self updateUploadProgress];
[self updateDownloadProgress];
}
}

}


Expand Down Expand Up @@ -519,7 +512,7 @@ - (void)updateDownloadProgress
{
unsigned long long bytesReadSoFar = totalBytesRead;

//We won't update download progress until we've examined the headers, since we might need to authenticate
// We won't update download progress until we've examined the headers, since we might need to authenticate
if (responseHeaders) {

if (bytesReadSoFar > lastBytesRead) {
Expand All @@ -528,8 +521,7 @@ - (void)updateDownloadProgress

if (downloadProgressDelegate) {


//We're using a progress queue or compatible controller to handle progress
// We're using a progress queue or compatible controller to handle progress
if ([downloadProgressDelegate respondsToSelector:@selector(incrementDownloadProgressBy:)]) {

NSAutoreleasePool *thePool = [[NSAutoreleasePool alloc] init];
Expand All @@ -554,7 +546,7 @@ - (void)updateDownloadProgress

[thePool release];

//We aren't using a queue, we should just set progress of the indicator to 0
// We aren't using a queue, we should just set progress of the indicator to 0
} else if (contentLength > 0) {
[ASIHTTPRequest setProgress:(double)(bytesReadSoFar/contentLength) forProgressIndicator:downloadProgressDelegate];
}
Expand All @@ -568,7 +560,7 @@ - (void)updateDownloadProgress
-(void)removeUploadProgressSoFar
{

//We're using a progress queue or compatible controller to handle progress
// We're using a progress queue or compatible controller to handle progress
if ([uploadProgressDelegate respondsToSelector:@selector(decrementUploadProgressBy:)]) {
unsigned long long value = 0-lastBytesSent;
SEL selector = @selector(decrementUploadProgressBy:);
Expand All @@ -579,7 +571,7 @@ -(void)removeUploadProgressSoFar
[invocation setArgument:&value atIndex:2];
[invocation invoke];

//We aren't using a queue, we should just set progress of the indicator to 0
// We aren't using a queue, we should just set progress of the indicator to 0
} else {
[ASIHTTPRequest setProgress:0 forProgressIndicator:uploadProgressDelegate];
}
Expand All @@ -598,11 +590,11 @@ + (void)setProgress:(double)progress forProgressIndicator:(id)indicator
NSMethodSignature *signature = [[indicator class] instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
float progressFloat = (float)progress; //UIProgressView wants a float for the progress parameter
float progressFloat = (float)progress; // UIProgressView wants a float for the progress parameter
[invocation setArgument:&progressFloat atIndex:2];
[invocation invokeWithTarget:indicator];

//If we're running in the main thread, update the progress straight away. Otherwise, it's not that urgent
// If we're running in the main thread, update the progress straight away. Otherwise, it's not that urgent
[invocation performSelectorOnMainThread:@selector(invokeWithTarget:) withObject:indicator waitUntilDone:[NSThread isMainThread]];


Expand Down Expand Up @@ -667,10 +659,10 @@ - (BOOL)readResponseHeadersReturningAuthenticationFailure
// Is the server response a challenge for credentials?
isAuthenticationChallenge = (responseStatusCode == 401);

//We won't reset the download progress delegate if we got an authentication challenge
// We won't reset the download progress delegate if we got an authentication challenge
if (!isAuthenticationChallenge) {

//See if we got a Content-length header
// See if we got a Content-length header
NSString *cLength = [responseHeaders valueForKey:@"Content-Length"];
if (cLength) {
contentLength = CFStringGetIntValue((CFStringRef)cLength);
Expand All @@ -682,15 +674,16 @@ - (BOOL)readResponseHeadersReturningAuthenticationFailure
}
}

//Handle cookies
// Handle cookies
NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:responseHeaders forURL:url];
[self setResponseCookies:cookies];

if (useCookiePersistance) {
//Store cookies in global persistent store

// Store cookies in global persistent store
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:cookies forURL:url mainDocumentURL:nil];

//We also keep any cookies in the sessionCookies array, so that we have a reference to them if we need to remove them later
// We also keep any cookies in the sessionCookies array, so that we have a reference to them if we need to remove them later
if (!sessionCookies) {
[ASIHTTPRequest setSessionCookies:[[[NSMutableArray alloc] init] autorelease]];
NSHTTPCookie *cookie;
Expand All @@ -711,7 +704,8 @@ - (BOOL)readResponseHeadersReturningAuthenticationFailure
- (void)saveCredentialsToKeychain:(NSMutableDictionary *)newCredentials
{
NSURLCredential *authenticationCredentials = [NSURLCredential credentialWithUser:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationUsername]
password:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationPassword] persistence:NSURLCredentialPersistencePermanent];
password:[newCredentials objectForKey:(NSString *)kCFHTTPAuthenticationPassword]
persistence:NSURLCredentialPersistencePermanent];

if (authenticationCredentials) {
[ASIHTTPRequest saveCredentials:authenticationCredentials forHost:[url host] port:[[url port] intValue] protocol:[url scheme] realm:authenticationRealm];
Expand Down Expand Up @@ -958,8 +952,6 @@ - (void)handleBytesAvailable

- (void)handleStreamComplete
{


//Try to read the headers (if this is a HEAD request handleBytesAvailable available may not be called)
if (!responseHeaders) {
if ([self readResponseHeadersReturningAuthenticationFailure]) {
Expand Down
1 change: 0 additions & 1 deletion ASINetworkQueueTests.m
Expand Up @@ -205,7 +205,6 @@ - (void)queueFinished:(ASINetworkQueue *)queue
{
complete = YES;
}




Expand Down

0 comments on commit 844d691

Please sign in to comment.