From 002cbe74afcf46397a34773cbf85a97260b3cf02 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Mon, 14 May 2012 16:57:39 -0700 Subject: [PATCH] Avoid appending empty form data parts. AFQueryStringComponentsFromKeyAndValue() always returns at least one component (even if its `value` parameter is `nil`). If a component doesn't have any form data, there's no need for us to append an empty, nameless part to the multipart body. Additional improvements to consider (which are not mutually exclusive with this change): - Don't run this loop at all when `parameters` is `nil`. - Change AFQueryStringComponentsFromKeyAndValue() to return an empty iterable when its `value` paramter is `nil`. --- AFNetworking/AFHTTPClient.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index b913da1..354aa21 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -509,7 +509,9 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { data = [[component.value description] dataUsingEncoding:self.stringEncoding]; } - [formData appendPartWithFormData:data name:[component.key description]]; + if (data) { + [formData appendPartWithFormData:data name:[component.key description]]; + } } if (block) {