From f762dc769c3be41503c37b7ecd56080f5e51e8f4 Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Tue, 6 Apr 2010 04:32:02 -0400 Subject: [PATCH] [Dox] Clean up TTURLRequest. --- src/TTRequestLoader.m | 2 +- src/TTURLImageResponse.m | 4 +-- src/TTURLRequest.m | 50 +++++++++++++++++++++++++------------- src/TTURLRequestQueue.m | 14 +++++------ src/Three20/TTURLRequest.h | 16 +++++++++--- 5 files changed, 56 insertions(+), 30 deletions(-) diff --git a/src/TTRequestLoader.m b/src/TTRequestLoader.m index 7996f5c3ac..0ed3b8bbdc 100644 --- a/src/TTRequestLoader.m +++ b/src/TTRequestLoader.m @@ -44,7 +44,7 @@ @implementation TTRequestLoader /////////////////////////////////////////////////////////////////////////////////////////////////// - (id)initForRequest:(TTURLRequest*)request queue:(TTURLRequestQueue*)queue { if (self = [super init]) { - _urlPath = [request.URL copy]; + _urlPath = [request.urlPath copy]; _queue = queue; _cacheKey = [request.cacheKey retain]; _cachePolicy = request.cachePolicy; diff --git a/src/TTURLImageResponse.m b/src/TTURLImageResponse.m index 1dded675d3..a91ada56e0 100644 --- a/src/TTURLImageResponse.m +++ b/src/TTURLImageResponse.m @@ -59,7 +59,7 @@ - (NSError*)request:(TTURLRequest*)request processResponse:(NSHTTPURLResponse*)r // TODO(jverkoey Feb 10, 2010): This logic doesn't entirely make sense. Why don't we just store // the data in the cache if there was a cache miss, and then just retain the image data we // downloaded? This needs to be tested in production. - UIImage* image = [[TTURLCache sharedCache] imageForURL:request.URL fromDisk:NO]; + UIImage* image = [[TTURLCache sharedCache] imageForURL:request.urlPath fromDisk:NO]; if (nil == image) { image = [UIImage imageWithData:data]; @@ -74,7 +74,7 @@ - (NSError*)request:(TTURLRequest*)request processResponse:(NSHTTPURLResponse*)r // NSData* data = UIImagePNGRepresentation(image); // [[TTURLCache sharedCache] storeData:data forURL:request.URL]; // } - [[TTURLCache sharedCache] storeImage:image forURL:request.URL]; + [[TTURLCache sharedCache] storeImage:image forURL:request.urlPath]; } _image = [image retain]; diff --git a/src/TTURLRequest.m b/src/TTURLRequest.m index 8da87f90b5..4ad372a150 100644 --- a/src/TTURLRequest.m +++ b/src/TTURLRequest.m @@ -32,7 +32,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// @implementation TTURLRequest -@synthesize URL = _URL; +@synthesize urlPath = _urlPath; @synthesize httpMethod = _httpMethod; @synthesize httpBody = _httpBody; @synthesize parameters = _parameters; @@ -77,7 +77,7 @@ + (TTURLRequest*)requestWithURL:(NSString*)URL delegate:(id /**/)delegate { if (self = [self init]) { - _URL = [URL retain]; + _urlPath = [URL retain]; if (nil != delegate) { [_delegates addObject:delegate]; } @@ -92,12 +92,7 @@ - (id)init { _delegates = TTCreateNonRetainingArray(); _cachePolicy = TTURLRequestCachePolicyDefault; _cacheExpirationAge = TT_DEFAULT_CACHE_EXPIRATION_AGE; - _isLoading = NO; _shouldHandleCookies = YES; - _totalBytesLoaded = 0; - _totalBytesExpected = 0; - _respondedFromCache = NO; - _filterPasswordLogging = NO; _charsetForMultipart = NSUTF8StringEncoding; } return self; @@ -106,7 +101,7 @@ - (id)init { /////////////////////////////////////////////////////////////////////////////////////////////////// - (void)dealloc { - TT_RELEASE_SAFELY(_URL); + TT_RELEASE_SAFELY(_urlPath); TT_RELEASE_SAFELY(_httpMethod); TT_RELEASE_SAFELY(_response); TT_RELEASE_SAFELY(_httpBody); @@ -118,18 +113,19 @@ - (void)dealloc { TT_RELEASE_SAFELY(_timestamp); TT_RELEASE_SAFELY(_files); TT_RELEASE_SAFELY(_delegates); + [super dealloc]; } /////////////////////////////////////////////////////////////////////////////////////////////////// - (NSString*)description { - return [NSString stringWithFormat:@"", _URL]; + return [NSString stringWithFormat:@"", _urlPath]; } /////////////////////////////////////////////////////////////////////////////////////////////////// -- (NSString *)md5HexDigest:(NSString*)input { +- (NSString*)md5HexDigest:(NSString*)input { const char* str = [input UTF8String]; unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5(str, strlen(str), result); @@ -146,7 +142,7 @@ - (NSString *)md5HexDigest:(NSString*)input { - (NSString*)generateCacheKey { if ([_httpMethod isEqualToString:@"POST"] || [_httpMethod isEqualToString:@"PUT"]) { - NSMutableString* joined = [[[NSMutableString alloc] initWithString:self.URL] autorelease]; + NSMutableString* joined = [[[NSMutableString alloc] initWithString:self.urlPath] autorelease]; NSEnumerator* e = [_parameters keyEnumerator]; for (id key; key = [e nextObject]; ) { [joined appendString:key]; @@ -159,15 +155,15 @@ - (NSString*)generateCacheKey { return [self md5HexDigest:joined]; } else { - return [self md5HexDigest:self.URL]; + return [self md5HexDigest:self.urlPath]; } } /////////////////////////////////////////////////////////////////////////////////////////////////// - (NSData*)generatePostBody { - NSMutableData *body = [NSMutableData data]; - NSString *beginLine = [NSString stringWithFormat:@"\r\n--%@\r\n", kStringBoundary]; + NSMutableData* body = [NSMutableData data]; + NSString* beginLine = [NSString stringWithFormat:@"\r\n--%@\r\n", kStringBoundary]; [body appendData:[[NSString stringWithFormat:@"--%@\r\n", kStringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; @@ -282,7 +278,7 @@ - (NSString*)cacheKey { /////////////////////////////////////////////////////////////////////////////////////////////////// -- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field { +- (void)setValue:(NSString*)value forHTTPHeaderField:(NSString*)field { if (!_headers) { _headers = [[NSMutableDictionary alloc] init]; } @@ -306,12 +302,12 @@ - (void)addFile:(NSData*)data mimeType:(NSString*)mimeType fileName:(NSString*)f - (BOOL)send { if (_parameters) { // Don't log passwords. Save now, restore after logging - NSString *password = [_parameters objectForKey:@"password"]; + NSString* password = [_parameters objectForKey:@"password"]; if (_filterPasswordLogging && password) { [_parameters setObject:@"[FILTERED]" forKey:@"password"]; } - TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"SEND %@ %@", self.URL, self.parameters); + TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"SEND %@ %@", self.urlPath, self.parameters); if (password) { [_parameters setObject:password forKey:@"password"]; @@ -339,4 +335,24 @@ - (NSURLRequest*)createNSURLRequest { } +/////////////////////////////////////////////////////////////////////////////////////////////////// +#pragma mark - +#pragma mark Properties + + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Deprecated +- (void)setURL:(NSString*)urlPath { + NSString* aUrlPath = [urlPath copy]; + [_urlPath release]; + _urlPath = aUrlPath; +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Deprecated +- (NSString*)URL { + return _urlPath; +} + @end diff --git a/src/TTURLRequestQueue.m b/src/TTURLRequestQueue.m index 73f8b19134..40efb7384f 100644 --- a/src/TTURLRequestQueue.m +++ b/src/TTURLRequestQueue.m @@ -153,7 +153,7 @@ - (BOOL)loadFromCache:(NSString*)URL cacheKey:(NSString*)cacheKey /////////////////////////////////////////////////////////////////////////////////////////////////// - (BOOL)loadRequestFromCache:(TTURLRequest*)request { if (!request.cacheKey) { - request.cacheKey = [[TTURLCache sharedCache] keyForURL:request.URL]; + request.cacheKey = [[TTURLCache sharedCache] keyForURL:request.urlPath]; } if (request.cachePolicy & (TTURLRequestCachePolicyDisk|TTURLRequestCachePolicyMemory)) { @@ -161,7 +161,7 @@ - (BOOL)loadRequestFromCache:(TTURLRequest*)request { NSDate* timestamp = nil; NSError* error = nil; - if ([self loadFromCache:request.URL cacheKey:request.cacheKey + if ([self loadFromCache:request.urlPath cacheKey:request.cacheKey expires:request.cacheExpirationAge fromDisk:!_suspended && request.cachePolicy & TTURLRequestCachePolicyDisk data:&data error:&error timestamp:×tamp]) { @@ -333,7 +333,7 @@ - (BOOL)sendRequest:(TTURLRequest*)request { } } - if (!request.URL.length) { + if (!request.urlPath.length) { NSError* error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadURL userInfo:nil]; for (id delegate in request.delegates) { if ([delegate respondsToSelector:@selector(request:didFailLoadWithError:)]) { @@ -365,7 +365,7 @@ - (BOOL)sendRequest:(TTURLRequest*)request { [_loaderQueue addObject:loader]; } else { ++_totalLoading; - [loader load:[NSURL URLWithString:request.URL]]; + [loader load:[NSURL URLWithString:request.urlPath]]; } [loader release]; @@ -385,7 +385,7 @@ - (BOOL)sendSynchronousRequest:(TTURLRequest*)request { } } - if (!request.URL.length) { + if (!request.urlPath.length) { NSError* error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadURL userInfo:nil]; for (id delegate in request.delegates) { if ([delegate respondsToSelector:@selector(request:didFailLoadWithError:)]) { @@ -403,7 +403,7 @@ - (BOOL)sendSynchronousRequest:(TTURLRequest*)request { // Should be decremented eventually by loadSynchronously ++_totalLoading; - [loader loadSynchronously:[NSURL URLWithString:request.URL]]; + [loader loadSynchronously:[NSURL URLWithString:request.urlPath]]; TT_RELEASE_SAFELY(loader); return NO; @@ -470,7 +470,7 @@ - (void)cancelAllRequests { /////////////////////////////////////////////////////////////////////////////////////////////////// - (NSURLRequest*)createNSURLRequest:(TTURLRequest*)request URL:(NSURL*)URL { if (!URL) { - URL = [NSURL URLWithString:request.URL]; + URL = [NSURL URLWithString:request.urlPath]; } NSMutableURLRequest* URLRequest = [NSMutableURLRequest requestWithURL:URL diff --git a/src/Three20/TTURLRequest.h b/src/Three20/TTURLRequest.h index 046e5159f6..a3abb9b406 100644 --- a/src/Three20/TTURLRequest.h +++ b/src/Three20/TTURLRequest.h @@ -16,6 +16,8 @@ #import "Three20/TTGlobalNetwork.h" +#import "Three20/TTCorePreprocessorMacros.h" + @protocol TTURLRequestDelegate; @protocol TTURLResponse; @@ -26,7 +28,7 @@ * processing using TTURLResponse objects. */ @interface TTURLRequest : NSObject { - NSString* _URL; + NSString* _urlPath; NSString* _httpMethod; NSData* _httpBody; @@ -60,9 +62,17 @@ } /** - * The URL to be loaded by the request. + * The URL path to be loaded by the request. + */ +@property (nonatomic, copy) NSString* urlPath; + +/** + * The URL path to be loaded by the request. + * + * Deprecated due to name ambiguity. Use urlPath instead. + * Remove after May 6, 2010. */ -@property (nonatomic, copy) NSString* URL; +@property (nonatomic, copy) NSString* URL __TTDEPRECATED_METHOD; /** * The HTTP method to send with the request.