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`.
This commit is contained in:
Jon Parise 2012-05-14 16:57:39 -07:00
parent ebdac4a01d
commit 002cbe74af

View file

@ -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) {