Fix deprecation warning in earlier change. Fixed a sequencing problem with the overloaded accessors on RKRequest

This commit is contained in:
Blake Watters
2011-01-06 14:51:44 -05:00
parent b31e6426a5
commit 0449380476
2 changed files with 20 additions and 20 deletions

View File

@@ -64,11 +64,23 @@
[super dealloc];
}
- (void)setRequestBody {
if (_params) {
// Prefer the use of a stream over a raw body
if ([_params respondsToSelector:@selector(HTTPBodyStream)]) {
[_URLRequest setHTTPBodyStream:[_params HTTPBodyStream]];
} else {
[_URLRequest setHTTPBody:[_params HTTPBody]];
}
}
}
- (void)addHeadersToRequest {
NSString* header;
for (header in _additionalHTTPHeaders) {
[_URLRequest setValue:[_additionalHTTPHeaders valueForKey:header] forHTTPHeaderField:header];
}
if (_params != nil) {
// Temporarily support older RKRequestSerializable implementations
if ([_params respondsToSelector:@selector(HTTPHeaderValueForContentType)]) {
@@ -80,6 +92,7 @@
[_URLRequest setValue:[NSString stringWithFormat:@"%d", [_params HTTPHeaderValueForContentLength]] forHTTPHeaderField:@"Content-Length"];
}
}
if (_username != nil) {
// Add authentication headers so we don't have to deal with an extra cycle for each message requiring basic auth.
CFHTTPMessageRef dummyRequest = CFHTTPMessageCreateRequest(kCFAllocatorDefault, (CFStringRef)[self HTTPMethod], (CFURLRef)[self URL], kCFHTTPVersion1_1);
@@ -94,24 +107,11 @@
NSLog(@"Headers: %@", [_URLRequest allHTTPHeaderFields]);
}
- (void)setMethod:(RKRequestMethod)method {
_method = method;
// Setup the NSURLRequest. The request must be prepared right before dispatching
- (void)prepareURLRequest {
[_URLRequest setHTTPMethod:[self HTTPMethod]];
}
- (void)setParams:(NSObject<RKRequestSerializable>*)params {
[params retain];
[_params release];
_params = params;
if (params && ![self isGET]) {
// Prefer the use of a stream over a raw body
if ([_params respondsToSelector:@selector(HTTPBodyStream)]) {
[_URLRequest setHTTPBodyStream:[_params HTTPBodyStream]];
} else {
[_URLRequest setHTTPBody:[_params HTTPBody]];
}
}
[self setRequestBody];
[self addHeadersToRequest];
}
- (NSString*)HTTPMethod {
@@ -140,7 +140,7 @@
- (void)fireAsynchronousRequest {
if ([[RKClient sharedClient] isNetworkAvailable]) {
[self addHeadersToRequest];
[self prepareURLRequest];
NSString* body = [[NSString alloc] initWithData:[_URLRequest HTTPBody] encoding:NSUTF8StringEncoding];
NSLog(@"Sending %@ request to URL %@. HTTP Body: %@", [self HTTPMethod], [[self URL] absoluteString], body);
[body release];
@@ -168,7 +168,7 @@
RKResponse* response = nil;
if ([[RKClient sharedClient] isNetworkAvailable]) {
[self addHeadersToRequest];
[self prepareURLRequest];
NSString* body = [[NSString alloc] initWithData:[_URLRequest HTTPBody] encoding:NSUTF8StringEncoding];
NSLog(@"Sending synchronous %@ request to URL %@. HTTP Body: %@", [self HTTPMethod], [[self URL] absoluteString], body);
[body release];

View File

@@ -76,7 +76,7 @@ static const NSInteger kMaxConcurrentLoads = 5;
- (void)loadNextInQueue {
// This makes sure that the Request Queue does not fire off any requests until the Reachability state has been determined.
// This prevents the request queue from
if ([[[RKClient client] baseURLReachabilityObserver] networkStatus] == RKReachabilityIndeterminate) {
if ([[[RKClient sharedClient] baseURLReachabilityObserver] networkStatus] == RKReachabilityIndeterminate) {
[self loadNextInQueueDelayed];
return;
}