diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 2e6d897..e0bf08b 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -176,7 +176,12 @@ class Curl } } - if (!$binary_data && (is_array($data) || is_object($data))) { + if (!$binary_data && + (is_array($data) || is_object($data)) && + ( + !isset($this->headers['Content-Type']) || + !preg_match('/^multipart\/form-data/', $this->headers['Content-Type']) + )) { $data = http_build_query($data, '', '&'); } diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index db5b197..66db23c 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -552,6 +552,28 @@ class CurlTest extends \PHPUnit\Framework\TestCase $this->assertEquals('image/png', $test->curl->response); } + public function testMultipartFormDataContentType() + { + // Use a PUT request instead of a POST request so the request + // multipart/form-data is not automatically parsed and can be tested + // against. + $test = new Test(); + $test->curl->setHeader('Content-Type', 'multipart/form-data'); + $test->server('put', 'PUT', array( + 'foo' => 'bar', + )); + + $this->assertEquals('100-continue', $test->curl->requestHeaders['Expect']); + $this->assertStringStartsWith('multipart/form-data; boundary=', $test->curl->requestHeaders['Content-Type']); + + $expected_contains = "\r\n" . + 'Content-Disposition: form-data; name="foo"' . "\r\n" . + "\r\n" . + 'bar' . "\r\n" . + ''; + $this->assertContains($expected_contains, $test->curl->response); + } + public function testPatchRequestMethod() { $test = new Test();