Unwind the unexpected behaviors in RKHTTPRequestOperation regarding Acceptable Content Types and Status Codes. Explicitly configure the needed types within RKObjectRequestOperation instead.

This commit is contained in:
Blake Watters
2012-09-12 21:21:46 -04:00
parent 94cbbb46c0
commit 3714dd4a56
7 changed files with 83 additions and 33 deletions

View File

@@ -20,16 +20,28 @@
#import "RKObjectRequestOperation.h"
#import "RKResponseMapperOperation.h"
#import "RKMIMETypeSerialization.h"
// Set Logging Component
#undef RKLogComponent
#define RKLogComponent lcl_cRestKitNetwork
static inline NSString * RKDescriptionForRequest(NSURLRequest *request)
static inline NSString *RKDescriptionForRequest(NSURLRequest *request)
{
return [NSString stringWithFormat:@"%@ '%@'", request.HTTPMethod, [request.URL absoluteString]];
}
static NSIndexSet *RKObjectRequestOperationAcceptableMIMETypes()
{
static NSMutableIndexSet *statusCodes = nil;
if (! statusCodes) {
statusCodes = [NSMutableIndexSet indexSet];
[statusCodes addIndexesInRange:RKStatusCodeRangeForClass(RKStatusCodeClassSuccessful)];
[statusCodes addIndexesInRange:RKStatusCodeRangeForClass(RKStatusCodeClassClientError)];
}
return statusCodes;
}
@interface RKObjectRequestOperation ()
@property (nonatomic, strong, readwrite) RKHTTPRequestOperation *requestOperation;
@property (nonatomic, strong, readwrite) NSArray *responseDescriptors;
@@ -57,6 +69,8 @@ static inline NSString * RKDescriptionForRequest(NSURLRequest *request)
self.request = request;
self.responseDescriptors = responseDescriptors;
self.requestOperation = [[RKHTTPRequestOperation alloc] initWithRequest:request];
self.requestOperation.acceptableContentTypes = [RKMIMETypeSerialization registeredMIMETypes];
self.requestOperation.acceptableStatusCodes = RKObjectRequestOperationAcceptableMIMETypes();
// Initialize avoidsNetworkAccess based on caching preferences
switch(self.request.cachePolicy) {
@@ -69,7 +83,6 @@ static inline NSString * RKDescriptionForRequest(NSURLRequest *request)
self.avoidsNetworkAccess = YES;
break;
};
// TODO: set acceptable MIME Types based on available serializations?
}
return self;