Permalink
Browse files

Made receivedData an NSMutableData object, to save all the casting

Changed url format in tests
Small layout cleanups in the nib
Added reference to the new documentation page
  • Loading branch information...
Ben Copsey
Ben Copsey committed Aug 1, 2008
1 parent 7b5dce9 commit d404ae181d1d71c01398809fdffdaf516178af2f
View
@@ -4,6 +4,9 @@
// Created by Ben Copsey on 04/10/2007.
// Copyright 2007-2008 All-Seeing Interactive. All rights reserved.
//
+// A guide to the main features is available at:
+// http://allseeing-i.com/asi-http-request
+//
// Portions are based on the ImageClient example from Apple:
// See: http://developer.apple.com/samplecode/ImageClient/listing37.html
@@ -68,7 +71,7 @@
BOOL haveExaminedHeaders;
//Data we receive will be stored here
- CFMutableDataRef receivedData;
+ NSMutableData *receivedData;
//Used for sending and receiving data
CFHTTPMessageRef request;
@@ -228,6 +231,6 @@
@property (retain) NSDictionary *responseHeaders;
@property (retain) NSDictionary *requestCredentials;
@property (assign) int responseStatusCode;
-
+@property (retain) NSMutableData *receivedData;
@end
View
@@ -4,6 +4,9 @@
// Created by Ben Copsey on 04/10/2007.
// Copyright 2007-2008 All-Seeing Interactive. All rights reserved.
//
+// A guide to the main features is available at:
+// http://allseeing-i.com/asi-http-request
+//
// Portions are based on the ImageClient example from Apple:
// See: http://developer.apple.com/samplecode/ImageClient/listing37.html
@@ -46,7 +49,7 @@ - (id)initWithURL:(NSURL *)newURL
//credentials = NULL;
request = NULL;
responseHeaders = nil;
- [self setUseKeychainPersistance:YES];
+ [self setUseKeychainPersistance:NO];
[self setUseSessionPersistance:YES];
didFinishSelector = @selector(requestFinished:);
didFailSelector = @selector(requestFailed:);
@@ -135,7 +138,7 @@ - (NSString *)dataString
if (!receivedData) {
return nil;
}
- return [[[NSString alloc] initWithBytes:[(NSData *)receivedData bytes] length:[(NSData *)receivedData length] encoding:NSUTF8StringEncoding] autorelease];
+ return [[[NSString alloc] initWithBytes:[receivedData bytes] length:[receivedData length] encoding:NSUTF8StringEncoding] autorelease];
}
@@ -237,7 +240,7 @@ - (void)loadRequest
lastBytesSent = 0;
contentLength = 0;
[self setResponseHeaders:nil];
- receivedData = CFDataCreateMutable(NULL, 0);
+ [self setReceivedData:[[[NSMutableData alloc] init] autorelease]];
// Create the stream for the request.
readStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,readStream);
@@ -302,8 +305,7 @@ - (void)cancelLoad
}
if (receivedData) {
- CFRelease(receivedData);
- receivedData = NULL;
+ [self setReceivedData:nil];
//If we were downloading to a file, let's remove it
} else if (downloadDestinationPath) {
@@ -659,7 +661,7 @@ - (void)handleBytesAvailable
//Otherwise, let's add the data to our in-memory store
} else {
- CFDataAppendBytes(receivedData, buffer, bytesRead);
+ [receivedData appendBytes:buffer length:bytesRead];
}
}
}
@@ -778,4 +780,5 @@ + (void)removeCredentialsForHost:(NSString *)host port:(int)port protocol:(NSStr
@synthesize responseHeaders;
@synthesize requestCredentials;
@synthesize responseStatusCode;
+@synthesize receivedData;
@end
View
@@ -62,23 +62,23 @@ - (void)testOperationQueue
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
NSURL *url;
- url = [[[NSURL alloc] initWithString:@"http:/allseeing-i.com/asi-http-request-tests/first"] autorelease];
+ url = [[[NSURL alloc] initWithString:@"http:/allseeing-i.com/asi-http-request/tests/first"] autorelease];
ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[queue addOperation:request1];
- url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request-tests/second"] autorelease];
+ url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/second"] autorelease];
ASIHTTPRequest *request2 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[queue addOperation:request2];
- url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request-tests/third"] autorelease];
+ url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/third"] autorelease];
ASIHTTPRequest *request3 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[queue addOperation:request3];
url = [[[NSURL alloc] initWithString:@"http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaab.com"] autorelease];
ASIHTTPRequest *request4 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[queue addOperation:request4];
- url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request-tests/broken"] autorelease];
+ url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/broken"] autorelease];
ASIHTTPRequest *request5 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[queue addOperation:request5];

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.

0 comments on commit d404ae1

Please sign in to comment.