mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-26 05:19:18 +00:00
Merge pull request #546 from zachborboa/master
Allow fileless requests to use Content-Type: multipart/form-data
This commit is contained in:
+6
-1
@@ -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, '', '&');
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user