Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solarium 3.x Solr 5.1.x Curl Adapter GET method fix
--- symfony/vendor/solarium/solarium/library/Solarium/Core/Client/Adapter/Curl.php (revision )
+++ symfony/vendor/solarium/solarium/library/Solarium/Core/Client/Adapter/Curl.php (revision )
@@ -155,10 +155,6 @@
curl_setopt($handler, CURLOPT_PROXY, $proxy);
}
- if (!isset($options['headers']['Content-Type'])) {
- $options['headers']['Content-Type'] = 'text/xml; charset=utf-8';
- }
-
// Try endpoint authentication first, fallback to request for backwards compatibility
$authData = $endpoint->getAuthentication();
if (empty($authData['username'])) {
@@ -181,6 +177,11 @@
if ($method == Request::METHOD_POST) {
curl_setopt($handler, CURLOPT_POST, true);
+ // fixme: unlikely for this to work, must need to know "real" content type of payload
+ if (!isset($options['headers']['Content-Type'])) {
+ $options['headers']['Content-Type'] = 'application/x-www-form-urlencoded';
+ }
+
if ($request->getFileUpload()) {
if (version_compare(PHP_VERSION, '5.5.0') >= 0) {
$curlFile = curl_file_create($request->getFileUpload());
@@ -189,6 +190,13 @@
curl_setopt($handler, CURLOPT_POSTFIELDS, array('content' => '@'.$request->getFileUpload()));
}
} else {
+ // fixme: "raw-data" is xml and not json for whatever reason
+ $uri = str_replace('wt=json', 'wt=xml', $uri);
+ // it will fail if param 'commit' isn't passed on
+ if (!strpos($uri, 'commit=true')) {
+ $uri .= '&commit=true';
+ }
+ curl_setopt($handler, CURLOPT_URL, $uri);
curl_setopt($handler, CURLOPT_POSTFIELDS, $request->getRawData());
}
} elseif ($method == Request::METHOD_GET) {
@@ -214,7 +222,8 @@
{
// @codeCoverageIgnoreStart
$options = array(
- 'timeout' => $endpoint->getTimeout()
+ 'timeout' => $endpoint->getTimeout(),
+ 'headers' => [],
);
foreach ($request->getHeaders() as $headerLine) {
list($header, $value) = explode(':', $headerLine);
@macedigital

This comment has been minimized.

Copy link
Owner Author

@macedigital macedigital commented Apr 23, 2015

YMMV: Hack to be able to use Solr 5.1.x in Symfony2 (nelmio/solarium-bundle v2.1.0 + solarium/solarium 3.3.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment