ZF-4236: POST field order not fully preserved when uploading files

Description

When you add both regular POST fields and file uploads in an HTTP request, the file uploads are always be sent after the regular fields, even if they were added before them the regular fields.

For example, if you have the following code:


$httpClient->setParameterPost('fieldA', 'valueA');
$httpClient->setFileUpload('filename.txt', 'fieldB', 'file contents', 'text/plain');
$httpClient->setParameterPost('fieldC', 'valueC');

Zend_Http_Client will reorder them as fieldA, fieldC, and fieldB when it sends it to the web server. I'm working with using Zend_Http_Client against a web application that is sensitive about the ordering of fields, and Zend_Http_Client's current behavior breaks this application.

I am attaching a patch that fixes this problem by preserving the order in which regular and file upload fields are added to Zend_Http_Client. With this patch, the field order for the previous example would be fieldA, fieldB, and fieldC.

Comments

I have refactored the previously posted patch and adapted it to ZF 1.9.2. I'm attaching it to this ticket.

I've attached a patch which implements the same functionality with less code and provides unit tests for the implementation.

Reviewed and applied Adam's patch to trunk and 1.11 release branch.