Skip to content

Commit

Permalink
Fixes bugs from PR 484; fix Http adapter for extraction requests
Browse files Browse the repository at this point in the history
  • Loading branch information
janusman authored and thePanz committed Jan 19, 2018
1 parent 3363bfe commit 0f9daaa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 14 additions & 10 deletions library/Solarium/Core/Client/Adapter/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,30 @@ public function check($data, $headers)
public function createContext($request, $endpoint)
{
$method = $request->getMethod();
$context = stream_context_create(
array('http' => array(
'method' => $method,
'timeout' => $endpoint->getTimeout(),
),
)
);
$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");
Expand Down

0 comments on commit 0f9daaa

Please sign in to comment.