Commit 574c0103 authored by Markus Kalkbrenner's avatar Markus Kalkbrenner

revert #484

parent aebed2ab
......@@ -111,25 +111,13 @@ class Http extends Configurable implements AdapterInterface
if ($method == Request::METHOD_POST) {
if ($request->getFileUpload()) {
$boundary = '----------' . md5(time());
$CRLF = "\r\n";
$file = $request->getFileUpload();
$filename = basename($file);
// Add the proper boundary to the Content-Type header
$request->addHeader("Content-Type: multipart/form-data; boundary={$boundary}");
$data = "--{$boundary}" . $CRLF;
$data .= 'Content-Disposition: form-data; name="upload"; filename=' . $filename . $CRLF;
$data .= 'Content-Type: application/octet-stream' . $CRLF . $CRLF;
$data .= file_get_contents($request->getFileUpload()) . $CRLF;
$data .= '--' . $boundary . '--';
$content_length = strlen($data);
$request->addHeader("Content-Length: $content_length\r\n");
stream_context_set_option(
$context,
'http',
'content',
$data
file_get_contents($request->getFileUpload())
);
$request->addHeader('Content-Type: multipart/form-data');
} else {
$data = $request->getRawData();
if (null !== $data) {
......
......@@ -107,6 +107,7 @@ class RequestBuilder extends BaseRequestBuilder
} elseif (is_readable($file)) {
$request->setFileUpload($file);
$request->addParam('resource.name', basename($query->getFile()));
$request->addHeader('Content-Type: multipart/form-data');
} else {
throw new RuntimeException('Extract query file path/url invalid or not available');
}
......
......@@ -184,20 +184,16 @@ class HttpTest extends \PHPUnit_Framework_TestCase
$context = $this->adapter->createContext($request, $endpoint);
// Remove content from comparison, since we can't determine the
// random boundary string.
$stream_context_get_options = stream_context_get_options($context);
unset($stream_context_get_options['http']['content']);
unset($stream_context_get_options['http']['header']);
$this->assertEquals(
array(
'http' => array(
'method' => $method,
'timeout' => $timeout,
'content' => file_get_contents(__FILE__),
'header' => 'Content-Type: multipart/form-data',
)
),
$stream_context_get_options
stream_context_get_options($context)
);
}
......
......@@ -134,7 +134,9 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
public function testContentTypeHeader()
{
$headers = array();
$headers = array(
'Content-Type: multipart/form-data'
);
$request = $this->builder->build($this->query);
$this->assertEquals($headers,
$request->getHeaders());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment