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
Showing
8 changed files
with
18 additions
and
12 deletions
| @@ -4,6 +4,9 @@ | @@ -4,6 +4,9 @@ | ||
| 4 | // Created by Ben Copsey on 04/10/2007. | 4 | // Created by Ben Copsey on 04/10/2007. |
| 5 | // Copyright 2007-2008 All-Seeing Interactive. All rights reserved. | 5 | // Copyright 2007-2008 All-Seeing Interactive. All rights reserved. |
| 6 | // | 6 | // |
| 7 | +// A guide to the main features is available at: | ||
| 8 | +// http://allseeing-i.com/asi-http-request | ||
| 9 | +// | ||
| 7 | // Portions are based on the ImageClient example from Apple: | 10 | // Portions are based on the ImageClient example from Apple: |
| 8 | // See: http://developer.apple.com/samplecode/ImageClient/listing37.html | 11 | // See: http://developer.apple.com/samplecode/ImageClient/listing37.html |
| 9 | 12 | ||
| @@ -68,7 +71,7 @@ | @@ -68,7 +71,7 @@ | ||
| 68 | BOOL haveExaminedHeaders; | 71 | BOOL haveExaminedHeaders; |
| 69 | 72 | ||
| 70 | //Data we receive will be stored here | 73 | //Data we receive will be stored here |
| 71 | - CFMutableDataRef receivedData; | 74 | + NSMutableData *receivedData; |
| 72 | 75 | ||
| 73 | //Used for sending and receiving data | 76 | //Used for sending and receiving data |
| 74 | CFHTTPMessageRef request; | 77 | CFHTTPMessageRef request; |
| @@ -228,6 +231,6 @@ | @@ -228,6 +231,6 @@ | ||
| 228 | @property (retain) NSDictionary *responseHeaders; | 231 | @property (retain) NSDictionary *responseHeaders; |
| 229 | @property (retain) NSDictionary *requestCredentials; | 232 | @property (retain) NSDictionary *requestCredentials; |
| 230 | @property (assign) int responseStatusCode; | 233 | @property (assign) int responseStatusCode; |
| 231 | - | 234 | +@property (retain) NSMutableData *receivedData; |
| 232 | 235 | ||
| 233 | @end | 236 | @end |
| @@ -4,6 +4,9 @@ | @@ -4,6 +4,9 @@ | ||
| 4 | // Created by Ben Copsey on 04/10/2007. | 4 | // Created by Ben Copsey on 04/10/2007. |
| 5 | // Copyright 2007-2008 All-Seeing Interactive. All rights reserved. | 5 | // Copyright 2007-2008 All-Seeing Interactive. All rights reserved. |
| 6 | // | 6 | // |
| 7 | +// A guide to the main features is available at: | ||
| 8 | +// http://allseeing-i.com/asi-http-request | ||
| 9 | +// | ||
| 7 | // Portions are based on the ImageClient example from Apple: | 10 | // Portions are based on the ImageClient example from Apple: |
| 8 | // See: http://developer.apple.com/samplecode/ImageClient/listing37.html | 11 | // See: http://developer.apple.com/samplecode/ImageClient/listing37.html |
| 9 | 12 | ||
| @@ -46,7 +49,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -46,7 +49,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 46 | //credentials = NULL; | 49 | //credentials = NULL; |
| 47 | request = NULL; | 50 | request = NULL; |
| 48 | responseHeaders = nil; | 51 | responseHeaders = nil; |
| 49 | - [self setUseKeychainPersistance:YES]; | 52 | + [self setUseKeychainPersistance:NO]; |
| 50 | [self setUseSessionPersistance:YES]; | 53 | [self setUseSessionPersistance:YES]; |
| 51 | didFinishSelector = @selector(requestFinished:); | 54 | didFinishSelector = @selector(requestFinished:); |
| 52 | didFailSelector = @selector(requestFailed:); | 55 | didFailSelector = @selector(requestFailed:); |
| @@ -135,7 +138,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -135,7 +138,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 135 | if (!receivedData) { | 138 | if (!receivedData) { |
| 136 | return nil; | 139 | return nil; |
| 137 | } | 140 | } |
| 138 | - return [[[NSString alloc] initWithBytes:[(NSData *)receivedData bytes] length:[(NSData *)receivedData length] encoding:NSUTF8StringEncoding] autorelease]; | 141 | + return [[[NSString alloc] initWithBytes:[receivedData bytes] length:[receivedData length] encoding:NSUTF8StringEncoding] autorelease]; |
| 139 | } | 142 | } |
| 140 | 143 | ||
| 141 | 144 | ||
| @@ -237,7 +240,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -237,7 +240,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 237 | lastBytesSent = 0; | 240 | lastBytesSent = 0; |
| 238 | contentLength = 0; | 241 | contentLength = 0; |
| 239 | [self setResponseHeaders:nil]; | 242 | [self setResponseHeaders:nil]; |
| 240 | - receivedData = CFDataCreateMutable(NULL, 0); | 243 | + [self setReceivedData:[[[NSMutableData alloc] init] autorelease]]; |
| 241 | 244 | ||
| 242 | // Create the stream for the request. | 245 | // Create the stream for the request. |
| 243 | readStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,readStream); | 246 | readStream = CFReadStreamCreateForStreamedHTTPRequest(kCFAllocatorDefault, request,readStream); |
| @@ -302,8 +305,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -302,8 +305,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 302 | } | 305 | } |
| 303 | 306 | ||
| 304 | if (receivedData) { | 307 | if (receivedData) { |
| 305 | - CFRelease(receivedData); | 308 | + [self setReceivedData:nil]; |
| 306 | - receivedData = NULL; | ||
| 307 | 309 | ||
| 308 | //If we were downloading to a file, let's remove it | 310 | //If we were downloading to a file, let's remove it |
| 309 | } else if (downloadDestinationPath) { | 311 | } else if (downloadDestinationPath) { |
| @@ -659,7 +661,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -659,7 +661,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 659 | 661 | ||
| 660 | //Otherwise, let's add the data to our in-memory store | 662 | //Otherwise, let's add the data to our in-memory store |
| 661 | } else { | 663 | } else { |
| 662 | - CFDataAppendBytes(receivedData, buffer, bytesRead); | 664 | + [receivedData appendBytes:buffer length:bytesRead]; |
| 663 | } | 665 | } |
| 664 | } | 666 | } |
| 665 | } | 667 | } |
| @@ -778,4 +780,5 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -778,4 +780,5 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 778 | @synthesize responseHeaders; | 780 | @synthesize responseHeaders; |
| 779 | @synthesize requestCredentials; | 781 | @synthesize requestCredentials; |
| 780 | @synthesize responseStatusCode; | 782 | @synthesize responseStatusCode; |
| 783 | +@synthesize receivedData; | ||
| 781 | @end | 784 | @end |
| @@ -62,15 +62,15 @@ More tests needed for: | @@ -62,15 +62,15 @@ More tests needed for: | ||
| 62 | NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; | 62 | NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; |
| 63 | 63 | ||
| 64 | NSURL *url; | 64 | NSURL *url; |
| 65 | - url = [[[NSURL alloc] initWithString:@"http:/allseeing-i.com/asi-http-request-tests/first"] autorelease]; | 65 | + url = [[[NSURL alloc] initWithString:@"http:/allseeing-i.com/asi-http-request/tests/first"] autorelease]; |
| 66 | ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 66 | ASIHTTPRequest *request1 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
| 67 | [queue addOperation:request1]; | 67 | [queue addOperation:request1]; |
| 68 | 68 | ||
| 69 | - url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request-tests/second"] autorelease]; | 69 | + url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/second"] autorelease]; |
| 70 | ASIHTTPRequest *request2 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 70 | ASIHTTPRequest *request2 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
| 71 | [queue addOperation:request2]; | 71 | [queue addOperation:request2]; |
| 72 | 72 | ||
| 73 | - url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request-tests/third"] autorelease]; | 73 | + url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/third"] autorelease]; |
| 74 | ASIHTTPRequest *request3 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 74 | ASIHTTPRequest *request3 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
| 75 | [queue addOperation:request3]; | 75 | [queue addOperation:request3]; |
| 76 | 76 | ||
| @@ -78,7 +78,7 @@ More tests needed for: | @@ -78,7 +78,7 @@ More tests needed for: | ||
| 78 | ASIHTTPRequest *request4 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 78 | ASIHTTPRequest *request4 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
| 79 | [queue addOperation:request4]; | 79 | [queue addOperation:request4]; |
| 80 | 80 | ||
| 81 | - url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request-tests/broken"] autorelease]; | 81 | + url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/asi-http-request/tests/broken"] autorelease]; |
| 82 | ASIHTTPRequest *request5 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; | 82 | ASIHTTPRequest *request5 = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; |
| 83 | [queue addOperation:request5]; | 83 | [queue addOperation:request5]; |
| 84 | 84 |
This diff is collapsed. Click to expand it.
No preview for this file type
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff was suppressed by a .gitattributes entry.
-
Please register or login to post a comment