diff --git a/Code/Network/RKRequest.h b/Code/Network/RKRequest.h index 2fc7f502d6..a651562658 100644 --- a/Code/Network/RKRequest.h +++ b/Code/Network/RKRequest.h @@ -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 diff --git a/Code/Network/RKRequest.m b/Code/Network/RKRequest.m index be5273290b..653e6babb7 100644 --- a/Code/Network/RKRequest.m +++ b/Code/Network/RKRequest.m @@ -365,12 +365,17 @@ - (void)addHeadersToRequest { // 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; } diff --git a/Code/ObjectMapping/RKObjectLoader.h b/Code/ObjectMapping/RKObjectLoader.h index 79cbf9a19a..36ceb02a73 100644 --- a/Code/ObjectMapping/RKObjectLoader.h +++ b/Code/ObjectMapping/RKObjectLoader.h @@ -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 *)serialization; + /** Sent when an object loader encounters a response status code or MIME Type that RestKit does not know how to handle. diff --git a/Code/ObjectMapping/RKObjectLoader.m b/Code/ObjectMapping/RKObjectLoader.m index 67fc97c8f3..fb46c67f04 100644 --- a/Code/ObjectMapping/RKObjectLoader.m +++ b/Code/ObjectMapping/RKObjectLoader.m @@ -351,6 +351,10 @@ - (BOOL)prepareURLRequest { [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; } diff --git a/Code/ObjectMapping/RKObjectSerializer.m b/Code/ObjectMapping/RKObjectSerializer.m index 1def68c982..42f9e52383 100644 --- a/Code/ObjectMapping/RKObjectSerializer.m +++ b/Code/ObjectMapping/RKObjectSerializer.m @@ -90,7 +90,7 @@ - (id)serializedObjectForMIMEType:(NSString*)MIMEType error:(NSError**)error { return nil; } -- (id)serializationForMIMEType:(NSString*)MIMEType error:(NSError**)error { +- (id)serializationForMIMEType:(NSString *)MIMEType error:(NSError **)error { if ([MIMEType isEqualToString:RKMIMETypeFormURLEncoded]) { // Dictionaries are natively RKRequestSerializable as Form Encoded return [self serializedObject:error];