Merge pull request #546 from zachborboa/master

Allow fileless requests to use Content-Type: multipart/form-data
This commit is contained in:
Zach Borboa
2018-09-08 00:28:13 -07:00
committed by GitHub
2 changed files with 28 additions and 1 deletions
+6 -1
View File
@@ -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, '', '&');
}
+22
View File
@@ -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();