Commit 0f9daaa6 authored by Alejandro Garza's avatar Alejandro Garza Committed by thePanz

Fixes bugs from PR 484; fix Http adapter for extraction requests

parent 3363bfe1
......@@ -2,6 +2,7 @@
## 3.x - Unreleased
- (backport) Fixes bugs from PR #484: fix Http adapter for extraction requests (PR #519)
- Updated PHP annotations and docblock (PR #526)
- Performance updates for formatting values (PR #485)
- Provide fluent interface (PR #483)
......
......@@ -101,26 +101,30 @@ class Http extends Configurable implements AdapterInterface
public function createContext($request, $endpoint)
{
$method = $request->getMethod();
$context = stream_context_create(
array('http' => array(
$context = stream_context_create(array(
'http' => array(
'method' => $method,
'timeout' => $endpoint->getTimeout(),
),
)
);
));
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
$headers = $request->getHeaders();
// Remove the Content-Type header, because we will replace it with something else.
if (($key = array_search("Content-Type: multipart/form-data", $headers)) !== false) {
unset($headers[$key]);
}
$request->setHeaders($headers);
$request->addHeader("Content-Type: multipart/form-data; boundary={$boundary}");
$data = "--{$boundary}" . $CRLF;
$data .= 'Content-Disposition: form-data; name="upload"; filename=' . $filename . $CRLF;
$data .= 'Content-Disposition: form-data; name="upload"; filename=' . $file . $CRLF;
$data .= 'Content-Type: application/octet-stream' . $CRLF . $CRLF;
$data .= file_get_contents($request->getFileUpload()) . $CRLF;
$data .= file_get_contents($file) . $CRLF;
$data .= '--' . $boundary . '--';
$content_length = strlen($data);
$request->addHeader("Content-Length: $content_length\r\n");
......
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