mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-17 23:14:56 +08:00
Added new pre-flight delegate callbacks for customization of RKRequest and RKObjectLoader instances before dispatch
This commit is contained in:
@@ -784,6 +784,14 @@ typedef void(^RKRequestDidFailLoadWithErrorBlock)(NSError *error);
|
||||
///-----------------------------------------------------------------------------
|
||||
/// @name Observing Request Progress
|
||||
///-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
Tells the delegate the request is about to be prepared for sending to the remote host.
|
||||
|
||||
@param request The RKRequest object that is about to be sent.
|
||||
*/
|
||||
- (void)requestWillPrepareForSend:(RKRequest *)request;
|
||||
|
||||
/**
|
||||
Sent when a request has started loading
|
||||
|
||||
|
||||
@@ -365,12 +365,17 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
|
||||
// Setup the NSURLRequest. The request must be prepared right before dispatching
|
||||
- (BOOL)prepareURLRequest {
|
||||
[_URLRequest setHTTPMethod:[self HTTPMethod]];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(requestWillPrepareForSend:)]) {
|
||||
[self.delegate requestWillPrepareForSend:self];
|
||||
}
|
||||
|
||||
[self setRequestBody];
|
||||
[self addHeadersToRequest];
|
||||
|
||||
NSString* body = [[NSString alloc] initWithData:[_URLRequest HTTPBody] encoding:NSUTF8StringEncoding];
|
||||
RKLogTrace(@"Prepared %@ URLRequest '%@'. HTTP Headers: %@. HTTP Body: %@.", [self HTTPMethod], _URLRequest, [_URLRequest allHTTPHeaderFields], body);
|
||||
[body release];
|
||||
[body release];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,16 @@ typedef void(^RKObjectLoaderDidLoadObjectsDictionaryBlock)(NSDictionary *diction
|
||||
*/
|
||||
- (void)objectLoaderDidFinishLoading:(RKObjectLoader *)objectLoader;
|
||||
|
||||
/**
|
||||
Informs the delegate that the object loader has serialized the source object into a serializable representation
|
||||
for sending to the remote system. The serialization can be modified to allow customization of the request payload independent of mapping.
|
||||
|
||||
@param objectLoader The object loader performing the serialization.
|
||||
@param sourceObject The object that was serialized.
|
||||
@param serialization The serialization of sourceObject to be sent to the remote backend for processing.
|
||||
*/
|
||||
- (void)objectLoader:(RKObjectLoader *)objectLoader didSerializeSourceObject:(id)sourceObject toSerialization:(inout id<RKRequestSerializable> *)serialization;
|
||||
|
||||
/**
|
||||
Sent when an object loader encounters a response status code or MIME Type that RestKit does not know how to handle.
|
||||
|
||||
|
||||
@@ -351,6 +351,10 @@
|
||||
[self didFailLoadWithError:error];
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(objectLoader:didSerializeSourceObject:toSerialization:)]) {
|
||||
[self.delegate objectLoader:self didSerializeSourceObject:self.sourceObject toSerialization:¶ms];
|
||||
}
|
||||
|
||||
self.params = params;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id<RKRequestSerializable>)serializationForMIMEType:(NSString*)MIMEType error:(NSError**)error {
|
||||
- (id<RKRequestSerializable>)serializationForMIMEType:(NSString *)MIMEType error:(NSError **)error {
|
||||
if ([MIMEType isEqualToString:RKMIMETypeFormURLEncoded]) {
|
||||
// Dictionaries are natively RKRequestSerializable as Form Encoded
|
||||
return [self serializedObject:error];
|
||||
|
||||
Reference in New Issue
Block a user