diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 00e8c67..ec25ed0 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -31,6 +31,10 @@ NSSet * AFContentTypesFromHTTPHeader(NSString *string) { _skippedCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@" ,"]; }); + if (!string) { + return nil; + } + NSScanner *scanner = [NSScanner scannerWithString:string]; scanner.charactersToBeSkipped = _skippedCharacterSet; @@ -226,7 +230,11 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { } + (BOOL)canProcessRequest:(NSURLRequest *)request { - return YES; + if (![[self class] isEqual:[AFHTTPRequestOperation class]]) { + return YES; + } + + return [[self acceptableContentTypes] intersectsSet:AFContentTypesFromHTTPHeader([request valueForHTTPHeaderField:@"Accept"])]; } @end diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m index 52426b1..ecfccd3 100644 --- a/AFNetworking/AFImageRequestOperation.m +++ b/AFNetworking/AFImageRequestOperation.m @@ -37,8 +37,6 @@ static dispatch_queue_t image_request_operation_processing_queue() { #elif __MAC_OS_X_VERSION_MIN_REQUIRED @property (readwrite, nonatomic, retain) NSImage *responseImage; #endif - -+ (NSSet *)defaultAcceptablePathExtensions; @end @implementation AFImageRequestOperation @@ -125,14 +123,6 @@ static dispatch_queue_t image_request_operation_processing_queue() { } #endif -+ (NSSet *)acceptableContentTypes { - return [NSSet setWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil]; -} - -+ (NSSet *)defaultAcceptablePathExtensions { - return [NSSet setWithObjects:@"tif", @"tiff", @"jpg", @"jpeg", @"gif", @"png", @"ico", @"bmp", @"cur", nil]; -} - - (id)initWithRequest:(NSURLRequest *)urlRequest { self = [super initWithRequest:urlRequest]; if (!self) { @@ -189,9 +179,6 @@ static dispatch_queue_t image_request_operation_processing_queue() { #pragma mark - AFHTTPClientOperation -+ (BOOL)canProcessRequest:(NSURLRequest *)request { - return [[[self class] acceptableContentTypes] containsObject:[request valueForHTTPHeaderField:@"Accept"]] || [[self defaultAcceptablePathExtensions] containsObject:[[request URL] pathExtension]]; -} #if __IPHONE_OS_VERSION_MIN_REQUIRED + (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest @@ -217,6 +204,20 @@ static dispatch_queue_t image_request_operation_processing_queue() { } #endif ++ (NSSet *)acceptableContentTypes { + return [NSSet setWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil]; +} + ++ (BOOL)canProcessRequest:(NSURLRequest *)request { + static NSSet * _acceptablePathExtension = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + _acceptablePathExtension = [[NSSet alloc] initWithObjects:@"tif", @"tiff", @"jpg", @"jpeg", @"gif", @"png", @"ico", @"bmp", @"cur", nil]; + }); + + return [_acceptablePathExtension containsObject:[[request URL] pathExtension]] || [super canProcessRequest:request]; +} + - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m index 651f2d7..451705e 100644 --- a/AFNetworking/AFJSONRequestOperation.m +++ b/AFNetworking/AFJSONRequestOperation.m @@ -35,8 +35,6 @@ static dispatch_queue_t json_request_operation_processing_queue() { @interface AFJSONRequestOperation () @property (readwrite, nonatomic, retain) id responseJSON; @property (readwrite, nonatomic, retain) NSError *JSONError; - -+ (NSSet *)defaultAcceptablePathExtensions; @end @implementation AFJSONRequestOperation @@ -61,18 +59,6 @@ static dispatch_queue_t json_request_operation_processing_queue() { return requestOperation; } -+ (NSSet *)acceptableContentTypes { - return [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil]; -} - -+ (NSSet *)defaultAcceptablePathExtensions { - return [NSSet setWithObjects:@"json", nil]; -} - -+ (BOOL)canProcessRequest:(NSURLRequest *)request { - return [[self acceptableContentTypes] containsObject:[request valueForHTTPHeaderField:@"Accept"]] || [[self defaultAcceptablePathExtensions] containsObject:[[request URL] pathExtension]]; -} - - (void)dealloc { [_responseJSON release]; [_JSONError release]; @@ -103,6 +89,16 @@ static dispatch_queue_t json_request_operation_processing_queue() { } } +#pragma mark - AFHTTPRequestOperation + ++ (NSSet *)acceptableContentTypes { + return [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil]; +} + ++ (BOOL)canProcessRequest:(NSURLRequest *)request { + return [[[request URL] pathExtension] isEqualToString:@"json"] || [super canProcessRequest:request]; +} + - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { diff --git a/AFNetworking/AFPropertyListRequestOperation.m b/AFNetworking/AFPropertyListRequestOperation.m index b5609b3..ecca1af 100644 --- a/AFNetworking/AFPropertyListRequestOperation.m +++ b/AFNetworking/AFPropertyListRequestOperation.m @@ -35,8 +35,6 @@ static dispatch_queue_t property_list_request_operation_processing_queue() { @property (readwrite, nonatomic, retain) id responsePropertyList; @property (readwrite, nonatomic, assign) NSPropertyListFormat propertyListFormat; @property (readwrite, nonatomic, retain) NSError *propertyListError; - -+ (NSSet *)defaultAcceptablePathExtensions; @end @implementation AFPropertyListRequestOperation @@ -63,14 +61,6 @@ static dispatch_queue_t property_list_request_operation_processing_queue() { return requestOperation; } -+ (NSSet *)acceptableContentTypes { - return [NSSet setWithObjects:@"application/x-plist", nil]; -} - -+ (NSSet *)defaultAcceptablePathExtensions { - return [NSSet setWithObjects:@"plist", nil]; -} - - (id)initWithRequest:(NSURLRequest *)urlRequest { self = [super initWithRequest:urlRequest]; if (!self) { @@ -108,8 +98,14 @@ static dispatch_queue_t property_list_request_operation_processing_queue() { } } +#pragma mark - AFHTTPRequestOperation + ++ (NSSet *)acceptableContentTypes { + return [NSSet setWithObjects:@"application/x-plist", nil]; +} + + (BOOL)canProcessRequest:(NSURLRequest *)request { - return [[[self class] acceptableContentTypes] containsObject:[request valueForHTTPHeaderField:@"Accept"]] || [[self defaultAcceptablePathExtensions] containsObject:[[request URL] pathExtension]]; + return [[[request URL] pathExtension] isEqualToString:@"plist"] || [super canProcessRequest:request]; } - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success diff --git a/AFNetworking/AFXMLRequestOperation.m b/AFNetworking/AFXMLRequestOperation.m index 25a3765..f40cacb 100644 --- a/AFNetworking/AFXMLRequestOperation.m +++ b/AFNetworking/AFXMLRequestOperation.m @@ -39,8 +39,6 @@ static dispatch_queue_t xml_request_operation_processing_queue() { @property (readwrite, nonatomic, retain) NSXMLDocument *responseXMLDocument; #endif @property (readwrite, nonatomic, retain) NSError *XMLError; - -+ (NSSet *)defaultAcceptablePathExtensions; @end @implementation AFXMLRequestOperation @@ -90,14 +88,6 @@ static dispatch_queue_t xml_request_operation_processing_queue() { } #endif -+ (NSSet *)acceptableContentTypes { - return [NSSet setWithObjects:@"application/xml", @"text/xml", nil]; -} - -+ (NSSet *)defaultAcceptablePathExtensions { - return [NSSet setWithObjects:@"xml", nil]; -} - - (void)dealloc { [_responseXMLParser release]; @@ -146,8 +136,14 @@ static dispatch_queue_t xml_request_operation_processing_queue() { self.responseXMLParser.delegate = nil; } +#pragma mark - AFHTTPRequestOperation + ++ (NSSet *)acceptableContentTypes { + return [NSSet setWithObjects:@"application/xml", @"text/xml", nil]; +} + + (BOOL)canProcessRequest:(NSURLRequest *)request { - return [[[self class] acceptableContentTypes] containsObject:[request valueForHTTPHeaderField:@"Accept"]] || [[self defaultAcceptablePathExtensions] containsObject:[[request URL] pathExtension]]; + return [[[request URL] pathExtension] isEqualToString:@"xml"] || [super canProcessRequest:request]; } - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success